Extension with registerProtocolHandler

378 views
Skip to first unread message

Jackie Han

unread,
Nov 10, 2022, 12:23:35 AM11/10/22
to Chromium Extensions
I tried to use `registerProtocolHandler()` in extension page. For example:

navigator.registerProtocolHandler("magnet", location.href + "?uri=%s", "Title");

It registers successfully. But when I click a magnet link in a web page, the browser navigate the page to chrome-extension://id/page.html?uri=.... , and you will see 
Screenshot 2022-11-10 at 12.54.39.png
I understand what happened. My question is that registerProtocolHandler is virtually unusable at the moment in extensions.

I searched a bit. There are some issues like crbug-86115 and crbug-1079333.

Simeon mentioned it in the past, but I don't think he's ever really used it.

Jackie Han

Stefan Van Damme

unread,
Nov 10, 2022, 2:48:31 AM11/10/22
to Chromium Extensions, Jackie Han
Hi Jackie,

That was my post :)
It will be a great addition to the Chrome extension experience.
I star that crbug. In my workaround, I use the conten_script to detect the hyperlinks on a web page, and with indexof  to "turnoffthelights" it opens that particular webpage. But that only works in the webpage content, not when you manually type it into the address bar.

Thanks,
Stefan vd

wOxxOm

unread,
Nov 10, 2022, 6:04:32 AM11/10/22
to Chromium Extensions, stefa...@gmail.com, Jackie Han
You need to use an html file and add it to web_accessible_resources, then it'll be usable

Jackie Han

unread,
Nov 10, 2022, 7:45:28 AM11/10/22
to wOxxOm, Chromium Extensions, stefa...@gmail.com
Thanks wOxxOm! After adding web_accessible_resources, the protocol links can navigate to the extension page.

Currently, Firefox supports protocol_handlers in manifest. And Chrome has a design doc for extensions. It seems that registerProtocolHandler and protocol_handlers are very similar. It seems that only using registerProtocolHandler is enough.

On the other hand, the user experience of simply redirecting a page to an extension page is not very good. For example, I'd like to keep the current page open and handle it with a background event, or open the extension page in a new tab or new window to handle it (maybe close it soon).

I'll think about what needs to be improved in this area. At the same time I opened an issue for discussing it.

wOxxOm

unread,
Nov 10, 2022, 10:04:36 AM11/10/22
to Chromium Extensions, Jackie Han, Chromium Extensions, stefa...@gmail.com, wOxxOm
FWIW when Shared Element Transitions API implements cross-origin support in the future it'll be possible to add a smooth page transition for the handler page like a fade-in or even something fancy similar to what Internet Explorer supported in the past.

Jackie Han

unread,
Dec 9, 2022, 4:45:41 AM12/9/22
to wOxxOm, Chromium Extensions, stefa...@gmail.com
Update: you can follow my proposal in the links below.

WECG for discussion extension behavior: https://github.com/w3c/webextensions/issues/317
WHATWG spec for registerProtocolHandler method: https://github.com/whatwg/html/issues/8596
Reply all
Reply to author
Forward
0 new messages