[w3c/ServiceWorker] can we host `serviceWorker.js` at different domain and register? (Issue #1634)

right now, there is a lot of confusion.
#578, says we can't use Blob file for the `scriptUrl`.
and 
#940, says it is a security issue that we can't use cross-origin url for `scriptUrl`

but #1307, says now it's possible to use cross-origin url for `scriptUrl`.

All I want to do is, have my, **`serviceworker.js`** file to host at `https://www.myworkerfile.com/serviceworker.js`

and another js file say **`library.js`** which will be probably a library hosted at `https://www.somcdn.com/library.js`
which will have the following code below, where you can see it exports function to window variable.
```js
        function registerServiceWorker() {
            navigator.serviceWorker.register("https://www.myworkerfile.com/serviceworker.js", { scope: "/" })
                .then(() => {
                    console.log('service worker has been regeisterd successfully')
                })
                .catch((err) => {
                    console.log('was not registerd properly')
                })
        }
        window.libraryExport  = {
            registerServiceWorker
        }
```

and now, i have my website, `www.myportfolio.com`, i will gladly include the above library through the script tag such as below

```html
<script src="https://www.somcdn.com/library.js" defer></script>
```
since the function will be available in window, i would gladly call 
```js
window.libraryExport.registerServiceWorker()
```

Now all I want to know is, will the service worker register successfully without any errors?, so that it intercepts all the network request in `www.myportfolio.com`

the reason for doing things like this is, we don't have permission to touch Actual code base and change the things, 
because to do so it will take lot of time, 
and we have 100's of website hosted from that code, so change in repository means change in 100's of website.

all we can do is by the way i have in mind above.

if we can't do it like above, could you please let me know what is alternative method ?



-- 
Reply to this email directly or view it on GitHub:
https://github.com/w3c/ServiceWorker/issues/1634
You are receiving this because you are subscribed to this thread.

Message ID: <w3c/ServiceWorker/issues/1634@github.com>

Received on Friday, 25 March 2022 09:54:16 UTC