Skip to content

FR: trying to get the FCM token silently #8815

@yairopro

Description

@yairopro

Operating System

macOS

Environment (if applicable)

Chrome Version 133.0.6943.127 (Official Build) (arm64)

Firebase SDK Version

11.2.0

Firebase SDK Product(s)

Messaging

Project Tooling

NextJS@15.1.5

Detailed Problem Description

The need:

In the firebase documentation, at this page, under "Basic best practices", it says in bold:

We strongly recommend your app retrieve this token at initial startup and save it to your app server

Therefore, at the start of my web-app, on client-side, I want to be able to try to get the FCM token silently, meaning that only if the notification permission is already granted, the function getToken() will return the token. Otherwise, if the permission is rejected or default, then it would throw an error accordingly.

Th current situation:

Given the notification permission status is default,
when I run getToken() at the start of the web-app,
the user is then requested for granting the notification-permission.

The demand:

Add a silent: boolean option to the getToken(messaging, options) function.

getToken(getMessaging(app), {
  vapidKey: "...",
  silent: true, // <-- 🤫
})

Given this option enabled, and the notification permission status is default,
then the getToken() function will throw an error instead of requesting the user the notification-permission.

Steps and code to reproduce issue

Given the notification-permission's status set to 'default', call getToken(), even without any parameter

Here's a minimal code for reproduction on stackblitz. You should run on a detached window rather than the side iframe in order to get the permission request.

Metadata

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