firebase / firebase/firebase-js-sdk

FR: Support serviceWorkerRegistration option for deleteToken

Open
#9,384 1 comment 0 reactions 0 assignees View on GitHub
api: messaging type: feature request
Dominant language
TypeScript
Stars
5.1k
Forks
1k
Avg merge
2d 21h
Merged PRs (30d)
37

Description

### Operating System

Windows 11

### Environment (if applicable)

Chrome 142.0.7444.163

### Firebase SDK Version

12.5.0

### Firebase SDK Product(s)

Messaging

### Project Tooling

Vue web app / PWA

### Detailed Problem Description

This may not be the correct category for this request, but I wanted to open a discussion in the correct place before filing a PR. I implemented a small change to improve the usage of `deleteToken()`, but while preparing a pull request, I saw the notice that public API changes are currently not being accepted. The notice recommended opening an issue instead, so here it is.

When using FCM with a custom service worker, `deleteToken()` can only be called reliably in the same session where `getToken()` was invoked. If `getToken()` is called, and then after a page reload or later session `deleteToken()` is called, the operation fails. The behavior is described in detail here and noted as a feature request:
https://github.com/firebase/firebase-js-sdk/issues/8621

The above issue provides workaround, and it does work, but it is not very discoverable, and it’s easy for developers using custom service workers to run into this issue. Especially since older versions of the SDK exposed `messaging.useServiceWorker(...)`, which made the dependency more clear. Today, only `getToken()` accepts a `serviceWorkerRegistration`, so it’s not obvious that `deleteToken()` implicitly depends on the same registration context.

To explore a potential improvement, I created a small change that adds an optional `serviceWorkerRegistration` parameter to `deleteToken()`, mirroring the existing pattern in `getToken()`. This change is backwards compatable as the new options are optional. I have a local PR in my fork if needed for reference:
https://github.com/HillBryan/firebase-js-sdk/pull/2

Is there an estimated timeline for when changes to the public APIs will be open for review?

Thank you!

### Steps and code to reproduce issue

Same as description

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.