Firebase Messaging Js Sdk Insights : getToken() : Part 1

Kumar Swapnil
1 min readMar 9, 2019

getToken() first check if the site has permission for showing Notification to the user. For this, it calls getNotificationPermission_() which uses Notification API to get the current permission. The code for getNotificationPermission_() is below.

If the site has been “granted” with permissions to show Notifications, getSWRegistration_() is called. This will register the default service worker and return the registration.

In the above function, the this.registrationToUse value is being set when we call the useServiceWorker() function on the firebase instance. The above function returns default activated service worker or the one that we passed into useServiceWorker(). The waitForRegistrationToActivate_() makes sure for the same. It waits for the service worker it relates to become active.

Coming back to the getToken() method, after getting the Service worker Registration object, it will call getPublicVapidKey_() which returns the default VAPID key or the uint8array version of the public VAPID key provided by the developer.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Kumar Swapnil
Kumar Swapnil

Written by Kumar Swapnil

Wallflower | Tsundoku | ❣️ anime and crypto

No responses yet

Write a response