Skip to content

firebase.messaging.getToken() seems to different for the window and the service worker, why? #220

@Dev-Fairbanks

Description

@Dev-Fairbanks

Hello,

I recently ran into this issue. I was attempting to get the current token for the user on the service worker.

My code on the service worker:

`firebase.initializeApp({
'messagingSenderId': '-'
})

let messaging = firebase.messaging();
let token = await messaging.getToken()
console.log(token);
`

My Code on the prompt event in the windowed webpage:
var config = { apiKey: "-", authDomain: "-", databaseURL: "-", projectId: "-", storageBucket: "", messagingSenderId: "-" }; firebase.initializeApp(config); messaging.requestPermission() .then(function () { getCurrentToken(); } //After user allows notifications function getCurrentToken(){ // Retrieve Firebase Messaging object. const messaging = firebase.messaging(); messaging.getToken() .then(function (currentToken) { console.log(currentToken); } }

Both calls gives me different

The interesting thing is if I use either token to send the notification to the client, it also works.

My question is why is there two different tokens from the initial allow event to the service worker on receive event. Is there something I am doing incorrectly? or is this an intended behavior.

Thanks in advance for your response.

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