- From: Jackie(Guokai) Han <notifications@github.com>
- Date: Fri, 09 Dec 2022 01:37:53 -0800
- To: w3c/ServiceWorker <ServiceWorker@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <w3c/ServiceWorker/issues/1665/1344075083@github.com>
I added issues in Chrome and Firefox's bug trackers respectively: [chromium-1399753](https://bugs.chromium.org/p/chromium/issues/detail?id=1399753) and [mozilla-1804856](https://bugzilla.mozilla.org/show_bug.cgi?id=1804856). Because Safari doesn't support `registerProtocolHandler`, I didn't add issue for Safari. Sync some information. For now, this is not a detailed design, but to ask whether browser vendors would like to support this function. ### Current Native Apps Behavior When 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 Behavior At 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 `target="_blank"` attribute, browser open the target URL in a new tab, but it depends on the websites, the developers who call registerProtocolHandler() can't control them. 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. ### Proposal I 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: ``` // in a web page of example.com // here add a new parameter, which tell the browser fire event in service worker and don't navigate current. navigator.registerProtocolHandler( "magnet", // protocal "https://example.com/add?uri=%s", // url {type: 'service-worker', navigation: 'none'} // new option object ); ``` ``` // in service worker of example.com self.addEventListener("protocol_handler", e => { let protocol = e.protocol; // "magnet" let link = e.originalLink; // the %s part }); ``` -- Reply to this email directly or view it on GitHub: https://github.com/w3c/ServiceWorker/issues/1665#issuecomment-1344075083 You are receiving this because you are subscribed to this thread. Message ID: <w3c/ServiceWorker/issues/1665/1344075083@github.com>
Received on Friday, 9 December 2022 09:38:06 UTC