Skip to content
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

Register a second SW on the same scope #2

Closed
ThomasPerraudin opened this issue Jul 12, 2017 · 6 comments
Closed

Register a second SW on the same scope #2

ThomasPerraudin opened this issue Jul 12, 2017 · 6 comments

Comments

@ThomasPerraudin
Copy link

I already have a service worker on my application, registered on the default scope "./"
It doesn't work with firebase-messaging-sw.js certainly because it is registered on the same scope.
Do you have a solution to register both service workers ?

@Nickersoft
Copy link
Owner

I actually wasn't aware you couldn't have multiple service workers registered in the same scope, though I assume that makes sense. You can change the location of the Firebase service worker script using:

Push.config({
  FCM: {
    serviceWorkerLocation: './yourLocation'
  }
});

If this helps. That way the scope of the Firebase service worker is limited to a subdirectory. Outside of that, it becomes more of a general service worker registration issue than an issue with this plugin.

@ThomasPerraudin
Copy link
Author

I agree it's a general issue with service workers. I think it happens when both service workers try to work with the same event listeners.

Changing the serviceWorkerLocation triggers an error :-(

The path of the provided scope ('/') is not under the max scope allowed ('/scripts/'). Adjust the scope, move the Service Worker script, or use the Service-Worker-Allowed HTTP header to allow the scope.

@Nickersoft
Copy link
Owner

So according to MDN:

The max scope for a service worker is the location of the worker

which sounds related to your issue. Could you describe your service worker setup in more detail / provide some code? Are you installing this plugin via NPM?

@ThomasPerraudin
Copy link
Author

I can provide you the full code : ccm.zip
You will find the application service worker at the bottom of app.js

@Nickersoft
Copy link
Owner

Hmm.. unfortunately, it does seem to boil down to the issue of overlapping ServiceWorker scopes. In fact, it seems there is an active discussion going on over on the W3 ServiceWorker spec repo about this very thing (see here and here). The best advice I can give, despite it being untested, is creating a single ServiceWorker called firebase-messaging-sw.js that uses the importScripts() method to import the two ServiceWorkers. You would just have to check to make sure you're not registering it twice. Sorry I can't be of more assistance.. unfortunately, I believe it's one of the limitations of ServiceWorkers. I'd suggest that you alter the scope, but then you wouldn't be able to register notifications from the homepage and whatnot.

@ThomasPerraudin
Copy link
Author

I've also seen that discution in the W3 repo. And I've tried to use importScripts but it doesn't fix the problem.
I hope the next generation of service workers will be far better, I'm sad to discover these big issues.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants