quickstart-js icon indicating copy to clipboard operation
quickstart-js copied to clipboard

Strange behaviour FCM token gets generated sometimes after many refresh.

Open sammyaxe opened this issue 5 years ago • 1 comments

Basically my issue is that I'm trying to enable push notifications via FCM. When obtaining token, I have used demo code. Everything works fine if I create standalone .html file and add my code. However if I add the same code at the very top of

tag before any other code in my WP build FCM token only gets generated after 3-4 hard refreshes.

I delete application each time I test this. On stand alone page FCM token gets generated from first load every time, on page that loads longer only after several attempts.

This has been driving me insane for a while now.

An error occurred while retrieving token.  FirebaseError: Messaging: A problem occured while subscribing the user to FCM: TypeError: Cannot read property 'json' of undefined (messaging/token-subscribe-failed).
    at Ce.<anonymous> (https://www.gstatic.com/firebasejs/7.6.0/firebase-messaging.js:1:24910)
    at https://www.gstatic.com/firebasejs/7.6.0/firebase-messaging.js:1:2010
    at Object.next (https://www.gstatic.com/firebasejs/7.6.0/firebase-messaging.js:1:2115)
    at n (https://www.gstatic.com/firebasejs/7.6.0/firebase-messaging.js:1:886)

sammyaxe avatar Mar 07 '20 20:03 sammyaxe

Found an issue, FCM has function fetch() if you have function of the same name, FCM functionality will break. I find it surprising that FCM library does not use prefix for function names.

sammyaxe avatar Mar 07 '20 22:03 sammyaxe