Skip to content

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

Open
@TomasHubelbauer

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.

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions