You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[REQUIRED] Describe the problem
Calling messaging getToken sometimes throws the error: Failed to execute 'subscribe' on 'PushManager': Subscription failed - no active Service Worker
This occurs when a user has not yet registered the service worker i.e. it is their first visit to the web app or their first usage of a feature that involves the use of the service worker -> since getToken does not register the SW until that point.
It seems there may be a race condition where the service worker may or may not be ready when const subscription = await swRegistration.pushManager.getSubscription(); is called here
I tried replicating and I wasn't able to reproduce the same behavior. I noticed that you are using an outdated SDK version, would you mind trying it out with the version 9.6.7 which is the latest for the official release. Would you mind trying to update the SDK version that you're using and see if the issue persists? If I can replicate the issue, I can have a better look into it. Please share a minimal, but complete sample of a project that I can run locally.
Hey @daedwards767. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!
Since there haven't been any recent updates here, I am going to close this issue.
@daedwards767 if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.
[REQUIRED] Describe your environment
[REQUIRED] Describe the problem
Calling messaging getToken sometimes throws the error:
Failed to execute 'subscribe' on 'PushManager': Subscription failed - no active Service Worker
This occurs when a user has not yet registered the service worker i.e. it is their first visit to the web app or their first usage of a feature that involves the use of the service worker -> since getToken does not register the SW until that point.
It seems there may be a race condition where the service worker may or may not be ready when
const subscription = await swRegistration.pushManager.getSubscription();
is called herefirebase-js-sdk/packages/messaging/src/internals/token-manager.ts
Line 159 in f5a1714
Other online sources here https://stackoverflow.com/questions/42063006/failed-to-subscribe-the-user-domexception-subscription-failed-no-active-serv and here bradtraversy/node_push_notifications#1 (comment) seem to solve this issue with the line
await navigator.serviceWorker.ready;
to wait for the service worker to be ready,This may be connected to issue 5797 here #5797.
Steps to reproduce:
Caveat: in most cases the steps below will not trigger the issue, it will only occur when the service worker is not ready
Relevant Code:
The text was updated successfully, but these errors were encountered: