firebase / firebase/firebase-js-sdk

Make it possible to pass configurations options to the service worker from the main thread

Open
#6,949 13 comments 2 reactions 0 assignees View on GitHub
api: messaging feature request needs-attention
Dominant language
TypeScript
Stars
5.1k
Forks
1k
Avg merge
2d 21h
Merged PRs (30d)
37

Description

Hi, I am following the documentation on how to use the Firebase JavaScript SDK, specifically I am interested in FCM:
https://firebase.google.com/docs/cloud-messaging/js/receive#setting_notification_options_in_the_service_worker

The documentation states that alongside the JS SDK itself, I have to add a SW file as per the link above. I did that. Now turning the sample code in the documentation into production-ready code, I am getting rid of the hardcoded configuration strings, pulling them from my app's configuration instead.

However I am running into an issue doing this for the service worker. I can't access the main thread directly from the service worker thread, so it appears my only option is to use something like MessageChannel, Broadcast or the Client API.

But I can't help but think this is a common scenario the SDK already has an answer for, or at least, should; would folks agree? Would it be possible to have the SDK ship an API method for passing configuration options to the worker and be able to pick up the payload in the worker and initialize the SDK there as well based on the passed options?

I can and will for now do this myself using Broadcast, but IMO service workers are super fiddly to set up and make work right so I'd trust an SDK-provided solution over my own.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.