-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get clicked registerProtocolHandler (protocol_handlers) links in background #317
Comments
Update: After adding It seems that Next, I want to discuss: What is the difference between them.The permission of Functionality and user experienceOn the other hand, the user experience of simply redirecting a web 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). |
|
Sync some information, from whatwg/html#8596 and w3c/ServiceWorker#1665 Current Native Apps BehaviorWhen click a registered protocol link, the native app is woken up and the link is passed to the app for processing. Note: the current page are not closed or navigate to other page, you can continue to click other links in the page that active the native app again. Current Web BehaviorAt present, when click a registered protocol link, Chrome navigate current page to the registered URL. In other words, current page is unload, you can't continue to click other links in this page. In some scenarios, this behavior is not expected, instead users expect the behavior like native apps. Of course, if the link has At present, the spec of registerProtocolHandler doesn't describe the detailed behavior what happen when click the link. The behavior depends on how the browser implements it. ProposalI hope registerProtocolHandler() can support native apps' behavior. When users click the link, fire an event with the link information in service worker, then the website(web app) can handle it in service worker, and the current page stay there. This approach is more flexible for developers, and the current page does not navigate to other page. For example, in service worker, developers can open a new tab or popup window, or active(focus) an already opened page or popup window to handle it. Below is a sample code for demonstration purpose:
1. PWA "protocol_handlers"https://developer.chrome.com/articles/url-protocol-handler/ 2. Firefox extension's "protocol_handlers"https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/protocol_handlers So both 1) and 2) are declarative ways, and are not general(universal) solution. My proposalMy proposal expands
|
If this proposal can't move forward in Web standards side, I think we can try the following improvements in browser extensions side.
If developers add this listener, then when user click a registered link, the browser don't navigate current page to |
The title of the Chromium issue was confusing, so to clarify: https://bugs.chromium.org/p/chromium/issues/detail?id=64100#c59 ; basically the owner of the extension code had concerns about the approach with |
@fred-wang Thanks for your explanation for the current status of Chrome. For me, both dynamic way( For example, there are many download(magnet) links on a typical BitTorrent website page, when the user clicks a link, the BitTorrent client downloads one, clicks another link and downloads another, and the current page does not change. But current behavior of Web protocol handler is that click a magnet link, goto handler page, then the user needs to go back to the previous page; then click next magnet link, goto handler page, then go back; click next link …… This behavior makes it impossible to use it in this scenario. So I thought of another alternative behavior. When the user clicks a link, instead of redirecting to the handler page, trigger a background event to tell me the link information. In browser extensions, background events are widely used to obtain information and process it. I think this is more reasonable. So I proposal a new behavior for standard Web and browser extensions (here). |
I'm trying to reactivate the discussion about the declarative approach implemented by Firefox to manage the custom handlers registration from extensions. It seems that Safari expressed support and it was suggested in the 2022-12-08 meeting to gather additional feedback form Chrome. As it was commented there were some concerns raised by the owners of the extension code during the discussion in the bug 64100, but 2 years passed since then. I tried to reactivate the discussion in the bug without much success so far, so perhaps we could revisit the topic again in the next meeting ? |
By the way, currently developers use content script as a workaround to protocol handler. For example:
Note: when user click the link, the page doesn't navigate to other page. The disadvantage of content scripts is that it needs host permissions. This is why I propose support for protocol handlers in service worker. See comment-1 and comment-2. |
In latest versions of Chrome (not sure from which version, but I can try to figure it out) extensions become privileged actors when it comes to use the registerProtocolHandler API. Hence, it's possible to register a custom handler just using this simple script run as service worker:
The service worker could be as simple as this:
And the register.html script just need to trigger the user gesture, mandatory to invoke the registerProtocolHandler API
|
The problem of using the extension's tab is that it has some usability drawbacks; the user would have to trigger the registration with an user gesture and give content twice to, basically, the same thing. |
This is not a drawback. Users only click a button and confirm it. You can add some description for this button. There is one more benefit: you can provide a button for |
Well, first users click to "install an extension" that they know what its for. Then they have to click a button to register the handler, and then grant the registration, again. |
This is a best practice. Other optional permissions do the same process. |
Except for the additional step of granting the handler registration. I mean, the usual workflow is to install + granting optional permissions, but in this case it seems there is one additional, and perhaps redundant, step. This is why I think the declarative approach provided by the Manifest's protocol_handler gives us some advantages. Users would be able to avoid the HTML api and grants the registration as an optional permission. |
Adding
supportive: chrome
It seems like the other part of this issue is about adding new events/ways to handle protocols without opening a page. I haven't discussed that. |
Sometimes I feel like the people in the video conference don't think deeply about what I'm saying. For example, in the first video conference about this issue, they thought they were talking about the manifest. But I'm talking about behavior when clicking on links. |
@oliverdunk Chrome team also support my idea (get clicked link info in service worker). In WICG/web-app-launch#86 , Chrome member would like to support |
So in the extension manifest, except |
Cool ! Thank you @oliverdunk for the effort to unblock this old issue. Would you mind then add some feedback on the Chrome bug 64100 that we have precisely for this ? We also have API Overview Doc that we could get back to live.
Yes, I think that's a different topic that deserves its own issue. Perhaps the HTML spec, where the Custom Handlers API is defined would be more appropriated. We would need first to ensure there is enough interest from major browser vendors. |
Yes, I think there was a confusion regarding this. As I said, this behavior is specified in the Custom Handlers section of the HTML spec: So if we want to change that behavior, that spec is where we would need to put our efforts on. |
This is why I created whatwg/html#8596 and w3c/ServiceWorker#1665 I commented at #317 (comment) I also commented at #317 (comment) (copy below again)
|
As commented before, declare protocol_handlers in manifest is not a blocker for developers, it can be workaround by |
My second comment in this issue already started talking about the click behavior (navigation behavior). It should not be confused with the manifest issue. Copy it below again:
|
To @javifernandez @oliverdunk @fred-wang and other people In order to distinguish these two different topics, I created a new issue #365 for "protocol_handlers" in manifest. Please discuss manifest issue in #365 . I will modify current issue's title and labels. |
I understand, however, we can change the HTML API from the Web Extensions spec; even though this issue may have had other purpose, it got a promising agreement between 3 major browser vendors about the implementation of the Web protocol_handlers property of the Web Extensions Manifest as the primary way to register custom handlers from extensions. IMHO, we should keep focus of this issue on that specific goal, and even close it with an agreement conclusions. We can discuss the changes you are proposing in the HTML API in the other issues you've mentioned. Hence, I'm not sure the change in the title helps to solve the confusion, as I don't think Web Extensions is the right place to change the behavior of the HTML API. |
I´d rather use a new issue for the change in the registerProtocolHandler, and as I commented, I don't think Extensions is the right venue for that. This issue has the explicit comments of the different browser vendors supporting the implementation of Manifest's protocol_handler, so it'd be better to get back the original title and even close the issue with an agreement. |
This issue doesn't change the HTML or Web Service Worker Spec, I reported my proposal in their repositories. Instead, this issue discusses how to resolve related issue independently in extensions. And I proposed further proposals(ideas) for extensions. How to register protocol handler is not the point here. I support both declarative and programmatic registration. I researched some history to understand the current state of protocol handler. Browser vendors haven't really discussed this issue in the past, they even didn't understand my main point. Don't worry, their comments here didn't go away, I move their position labels to #365 . |
The Custom Handlers section, where the registerProtocolHandler HTML API is defined, states also the browser's behavior should use the registered protocol, not only the registration process. It states: Where the Navigate actions is also precisely specified. Isn't that the behavior you are proposing to change ? |
I'm not sure if it's necessary to modify HTML's API, which is a meeting point for several related areas.
It may also be resolved by "Web App Launch Handling" in PWA. So, extensions may also be supported in the same way.
Like PWA Launch Handling behavior, it can bring some information (e.g. a URL or a FileHandle) to developers' callback. So extensions may also be supported in the same way. By the way, why Chrome would like to support "protocol_handlers" in manifest now? [oliverdunk] said PS: registerProtocolHandler is a very old API that has not been significantly improved over the years, and some of its own problems have prevented it from being widely used by Web developers. So, in addition to extensions, I also want to push for improvements in Web standards. |
I'm sorry you feel that way, and I really appreciate you bringing it up. It's definitely not the intention. In this case, I think we realised during the meetings that there was a small change which we could all agree on and make in the short term. Consequently, discussion moved on to that. You did the right thing by pointing out you'd still like to see the larger change to how protocols are opened discussed. I think personally I would've preferred to keep this issue as is and open a new one for the new event, but given things have already been changed around, I think we should probably leave them as they are.
Done! |
@hanguokai To summarise from today's meeting (notes), it'd be interesting to write down a few cases (including your BitTorrent one) where this would be useful. Also - do you have thoughts on if just immediately closing the extension page would work? Clearly that's a bit of a workaround, but it seems like something that may help a little. |
This is not a feasible solution. For details, see my previous comments whatwg/html#8596 or #317 (comment) and whatwg/html#8596 (comment) . I have given a workaround in my previous comment, see #317 (comment) . |
registerProtocolHandler can't work in extensions
Standard Web has
navigator.registerProtocolHandler
method. But in my test, it can't work in extensions. On Chrome, in fact,registerProtocolHandler()
itself registers successfully, but the browser can't navigate the page to an extension link.Extension version of registerProtocolHandler
Firefox supports protocol_handlers.
Chrome is implementing this feature (since years ago).
I created this issue here hoping to move it forward. It is useful if extensions can registerProtocolHandler(well known protocol or custom protocol). Without this feature, developers need to register content scripts to handle it that need host permissions, or context menu(let users right click links).
The text was updated successfully, but these errors were encountered: