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

Event handler must be added on the initial evaluation of worker script #7937

Open
stefan-krajnik opened this issue Jan 10, 2024 · 5 comments

Comments

@stefan-krajnik
Copy link

Operating System

macOS Ventura 13.0

Browser Version

Google Chrome Version 120.0.6099.199 (Official Build) (arm64)

Firebase SDK Version

9.22.0

Firebase SDK Product:

Messaging

Describe your project's tooling

React app with Webpack

Describe the problem

I've been seeing these errors in sentry for a while, they come from service worker file even if I register service worker only if isSupported() passes.

This browser doesn't support indexedDb.open() (ex. Safari iFrame, Firefox Private Browsing, etc) (messaging/indexed-db-unsupported).

So I decided to do the same check in service worker but I'm getting these warnings if I call getMessaging asynchronously after isSupported() is resolved (see the screenshot)

Event handler of 'push' event must be added on the initial evaluation of worker script
Event handler of 'pushsubscriptionchange' event must be added on the initial evaluation of worker script.
Event handler of 'notificationclick' event must be added on the initial evaluation of worker script.
295329942-1cdebf24-4e3c-4e85-8c94-19072d46f3ba

Can you please confirm my approach with calling getMessaging asynchronously only if isSupported is correct ? If not what is the correct way using isSupported in service worker to prevent getting the error mentioned at the beginning ?

Steps and code to reproduce issue

  • call getMessaging asynchronously in your firebase-messaging-sw.js file
@stefan-krajnik stefan-krajnik added new A new issue that hasn't be categoirzed as question, bug or feature request question labels Jan 10, 2024
@jbalidiong jbalidiong added needs-attention and removed new A new issue that hasn't be categoirzed as question, bug or feature request labels Jan 10, 2024
@Santas
Copy link

Santas commented Jan 23, 2024

+1

@patrikholcak
Copy link

Any news on this? I couldn’t find any official documentation on the usage. Some of the code I found on github uses it the same way OP does, but then it prints the warnings

@stefan-krajnik
Copy link
Author

The issue is still present in v10.8.0

@Santas
Copy link

Santas commented Jun 3, 2024

@jbalidiong what is the best way to get help regarding this issue?

@jdeepwell
Copy link

I ran into this error message too. If I understand correctly, the initialisation of Firebase Push MUST happen in the global scope of the service worker during its initial evaluation – meaning: You cannot call initializeApp/getMessaging asynchronously. They MUST be called immediately when the global scope of the service worker script is first run.

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

No branches or pull requests

6 participants