firebase / firebase/firebase-js-sdk
Event handler must be added on the initial evaluation of worker script
- Dominant language
- TypeScript
- Stars
- 5.1k
- Forks
- 1k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 37
Description
### 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.
```
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
Contributor guide
Research direction
Start with the firebase-messaging-sw.js reproduction and trace the asynchronous getMessaging call relative to isSupported(). Reproduce the Chrome service-worker warnings and determine the expected behavior for supported and unsupported IndexedDB environments. Done means the correct service-worker usage is confirmed or documented and the reported warnings are addressed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- firebase, javascript, react, typescript, webpack
- Domain
- web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100