Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Service worker registration at custom scope #1449

Open
damooo opened this issue Aug 27, 2020 · 4 comments
Open

Service worker registration at custom scope #1449

damooo opened this issue Aug 27, 2020 · 4 comments

Comments

@damooo
Copy link

damooo commented Aug 27, 2020

Presently sapper generates code to automatically register service-worker, if one exists. But We cannot pass custom parameters at time of registering. For example in this case we want to set scope value, so that we can mount app at custom mount point. But cannot be done now.

Describe the solution you'd like
Allow configurable service worker registration.

Additional context
Here seems the code that's registering service worker:

script += `if('serviceWorker' in navigator)navigator.serviceWorker.register('${req.baseUrl}/service-worker.js');`;

related: #744

@antony
Copy link
Member

antony commented Aug 27, 2020

You can set the baseUrl as follows: https://sapper.svelte.dev/docs#Base_URLs

@damooo
Copy link
Author

damooo commented Aug 27, 2020

@antony setting baseUrl, currently configures only routes. But service worker scope being not derived from it. Thus It will be assumed ./ by browser, where start_url is root. And app is not being treated as pwa with following error.


Does not register a service worker that controls page and start_url
This page is controlled by a service worker,
    however the `start_url` (https://r1.example.org/) is not in the service worker's scope (https://r1.example.org/mount_path/)

@damooo
Copy link
Author

damooo commented Aug 27, 2020

@damooo
Copy link
Author

damooo commented Aug 27, 2020

Ok, service worker seems registering at app_root by default itself. so it is proper behaviour only. problem lies in manifest.json, wher start_url is setted to absolute root instead of app root. I filed an issue at sapper-template here: sveltejs/sapper-template#255

And still, it will be great if we can configure service-worker in general.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants