Search code examples
firebasecookiesbrowserpush-notificationfirebase-cloud-messaging

Where are Firebase (FCM) Tokens Stored for Web Push Notifications?


I'm currently working on integrating Firebase Cloud Messaging (FCM) for push notifications in my web application.
I have a question regarding the storage of FCM registration tokens and how they are impacted by actions such as clearing cookies.

As far as I understand, when a user grants permission for push notifications on a website, and then I call the getMessaging().getToken().then(token)..., the registration token associated with that permission is stored somewhere, because if I close and open the browser again, I get the same token, so it got to be saved locally somewhere, the question is where?
I'm uncertain about the impact of clearing cookies, history and browser data on the FCM registration tokens.

My specific questions are:

  1. If a user clears only cookies without targeting other site data, such as IndexedDB, will the FCM registration token remain intact?

  2. Are there any scenarios in which clearing cookies alone would result in the loss or resetting of FCM registration tokens?

  3. What are the best practices for ensuring that FCM registration tokens are retained even if a user clears cookies or performs similar actions?

  4. Where exactly the tokens are being saved and what different types of storage exist in the browser?

I would greatly appreciate any insights or clarifications on this matter.
Additionally, if there are any resources or documentation that provide more detailed information about the storage and management of FCM registration tokens in web push notifications, I would be grateful for references to those as well.


Solution

  • The FCM token is not stored in the cookies for your site. If it were, it'd be sent to the server with every request the app makes, which is not necessary. Hence clearing the cookies of a site will not wipe the FCM token for that site.

    A quick look through the source code for the FCM SDK seems to indicate that it is stored in the IndexedDB database of the browser.