w3c / ServiceWorker

Service Workers
https://w3c.github.io/ServiceWorker/
Other
3.63k stars 313 forks source link

register service worker on another domain #1631

Open jimmywarting opened 2 years ago

jimmywarting commented 2 years ago

With Web Share 2.0 it will be possible to share files to other domains.

If i am on page a.com and i wish to share something, and i happen to know another grate service that can handle those file on b.com, then that service also needs to install their service worker and set up share_target in the manifest.

but the visitor have never visited b.com and registered it before...

So the question really is: how can i make it so a.com can trigger b.com to register their service worker even before he/she have visited that page. One solution i can think of is to create a hidden iframe that installs the service worker. But the the problem with 3th party cookies kicks in and you won't be able to install the service worker.

is there some solution to register a foreign service worker?

jakearchibald commented 2 years ago

I'm not aware of a solution to this unfortunately. As you say, the third party stuff gets in the way.

However, Web Share implementations currently require the app to be added to the homescreen, right?

jimmywarting commented 2 years ago

I haven't currently dig into web share so much as atm, web share is still not so wildly adopted (chrome only did something for windows and android - can't test it in Mac), so i'm currently looking into a solution that can instead POST a <form target="https://b.com"> from a.com if that can be possible. But it first has to have registered a service worker and be able to handle (intercept fetch events)

I'm also thinking of other postMessage solutions too atm. but i would like to avoid iframes if at all possible. hidden iframes could be a nice solution to install service worker, save something in indexeddb and then navigate to the external service.

or something even more crazier like > navigate to b.com > install a service worker on b.com > redirect back to a.com where you came from > then make a form submit to b.com from a.com But this might be a bit bizarre if i'm only doing this to get around a problem with 3th party cookies being disabled...

I have found one other possible solution to install a service worker on another domain with the Web Payment api a long time ago when i played with it, but i'm not so sure about that, think it requires a payment dialog popup to even install the service worker on an external domain...

maybe i can use portals and postMessage also to do some magic, going to look into that as well...


Web share seems to really be the best solution of what i want to accomplish. but its bad that i can't suggest a external domain that can be able to handle/preview zip files (that is what i'm trying to share/build). Bit annoying that they would have to first install the app to the homescreen first