Skip to content

getToken in Android Chrome fails w/ DOMException: Registration failed - push service error on getToken #152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Matt-Jensen opened this issue Sep 2, 2017 · 5 comments

Comments

@Matt-Jensen
Copy link

Matt-Jensen commented Sep 2, 2017

[REQUIRED] Describe your environment

  • Operating System version: Android Galaxy S8
  • Firebase SDK version: 4.3.0
  • Firebase Product: messaging

[REQUIRED] Describe the problem

When requesting a registration token, w/ Chrome running on Android devices, the request is rejected with the following error message:
DOMException: Registration failed - push service error

Please note I was able to successfully trigger push notifications with the following:

curl -X POST -H "Authorization: key=AAAAgYxQHeQ:APA91bG9v5eZxk6a-ugXhymJRnRKpZ6Tp-11esJpdJsF1eme4HL_8_yCiTetBr7Rin4bVCBNF1nL9bBLqpKlZDoxm5ql_y7SqdY5exIBmKQ8wla_Zdur0mjtJcVcfMW668LmAmQ6P4p9" -H "Content-Type: application/json" -d '{
  "notification": {
    "title": "Portugal vs. Denmark",
    "body": "5 to 1",
    "icon": "firebase-logo.png",
    "click_action": "https://firebase-messaging-error.herokuapp.com/"
  },
  "to": "<REG_TOKEN_INSTANCE_ID>"
}' "https://fcm.googleapis.com/fcm/send"

on Chrome desktop.

Steps to reproduce:

I have recreated and published the example code from firebase/quickstart-js/messaging at this heroku application. To recreate this error visit this application with an android device and click the "request permission" which will invoke the getToken method. You should see the above error message logged in your console.

Relevant Code:

I have published the code of the above application here. The code that triggers the error is here.

Thanks in advance for your help!

@Matt-Jensen Matt-Jensen changed the title Firebase messaging in Android Chrome fails w/ DOMException: Registration failed - push service error on getToken getToken in Android Chrome fails w/ DOMException: Registration failed - push service error on getToken Sep 4, 2017
@gauntface
Copy link

Have you tried running your web app on other versions of Chrome? (Chrome beta and Chrome Dev).

Also what version of Chrome is running that is throwing the error (Settings > About Chrome)?

The error sounds like there is an issue with push service. Normally this is the result of Chrome ending up with a corrupt database.

@Matt-Jensen
Copy link
Author

Chrome 50.0.3029.83

@gauntface
Copy link

Ah, I suspect this is an issue in Chrome 50 that is fixed in newer versions of Chrome. This bug was closed with the same error message with no real solution: https://bugs.chromium.org/p/chromium/issues/detail?id=464365

I tried your demo on Chrome for Android Stable (61.0.3163.98) and got a token without an issue.

@Matt-Jensen
Copy link
Author

Thanks for confirming, I think future users will find this useful. While I do have concerns about the usefulness of the error message, I'm closing this issue because it does not originate with firebase-js-sdk.

@vinayakvanarse
Copy link

Hi, I have a similar problem. I have a PWA app using Polymer 2.0 and firebase. Firebase messaging is throwing very similar error.

ncaught (in promise) DOMException: Registration failed - push service error
Promise.then (async)
refreshToken @ firebase-messaging.html:87
activateMessaging @ firebase-messaging.html:125
activate @ firebase-messaging.html:243
_bootstrapApp @ firebase-messaging.html:259
runMethodEffect @ property-effects.html:813
runEffectsForProperty @ property-effects.html:159
runEffects @ property-effects.html:125
_propertiesChanged @ property-effects.html:1703
_flushProperties @ properties-changed.html:338
_flushProperties @ property-effects.html:1551
_invalidateProperties @ property-effects.html:1523
_setProperty @ property-effects.html:1508
Object.defineProperty.set @ properties-changed.html:150
__appNameChanged @ firebase-common-behavior.html:47
runObserverEffect @ property-effects.html:214
runEffectsForProperty @ property-effects.html:159
runEffects @ property-effects.html:125
_propertiesChanged @ property-effects.html:1703
_flushProperties @ properties-changed.html:338
_flushProperties @ property-effects.html:1551
ready @ property-effects.html:1656
ready @ element-mixin.html:546
ready @ dir-mixin.html:140
ready @ legacy-element-mixin.html:198
ready @ class.html:232
ready @ class.html:232
ready @ class.html:232
_enableProperties @ properties-changed.html:321
connectedCallback @ properties-mixin.html:208
connectedCallback @ element-mixin.html:532
connectedCallback @ dir-mixin.html:150
connectedCallback @ legacy-element-mixin.html:105
_attachDom @ element-mixin.html:588
_readyClients @ element-mixin.html:561
_flushClients @ property-effects.html:1565
_propertiesChanged @ property-effects.html:1699
_flushProperties @ properties-changed.html:338
_flushProperties @ property-effects.html:1551
ready @ property-effects.html:1656
ready @ element-mixin.html:546
ready @ my-app.html:540
_enableProperties @ properties-changed.html:321
connectedCallback @ properties-mixin.html:208
connectedCallback @ element-mixin.html:532
(anonymous) @ my-app.html:849

The messaging doesn't work in Chrome Desktop - [Google Chrome is up to date
Version 66.0.3359.139 (Official Build) (64-bit)] as well as in Chrome Android - [Application version Chrome 66.0.3359.126

Code used

my-app.html (PolymerElement)

<script src="bower_components/firebase/firebase-app.js"></script> <script src="bower_components/firebase/firebase-auth.js"></script> <script src="bower_components/firebase/firebase-database.js"></script> <script src="bower_components/firebase/firebase-firestore.js"></script> <script src="bower_components/firebase/firebase-messaging.js"></script> <script src="bower_components/firebase/firebase-storage.js"></script>


<firebase-auth
    id="auth"
    user="{{user}}"
    signed-in="{{signedIn}}"
    status-known="{{statusKnown}}"
    on-error="_handleError">
</firebase-auth>

<firebase-messaging
        id="messaging"
        token="{{token}}"
        on-message="handleMessage"
        active="{{fcmActive}}"
        status-known="{{fcmStatusKnown}}">
</firebase-messaging>

<firebase-document path="/users/[[user.uid]]/token" data="{{tokenDocVal}}">
</firebase-document>

class MyApp extends Polymer.Element {
static get is() { return 'my-app'; }

  ready() {
    this.addEventListener('request-fcm-permission', this._requestFcmPermission);
    super.ready();
  }

_requestFcmPermission() {
var fcm = this.$.messaging;
var self = this;
if (this.user && !fcm.active) {
fcm.requestPermission()
.then(function(){
console.log('FCM permission granted');
console.log('[[token]] ->' + self.token);
self.tokenDocVal = self.token;
})
.catch(function(e){
console.warn('FCM permission blocked', e);
})
}
}

... other html code ....

And the firebase-messaging-sw.js

importScripts('/bower_components/firebase/firebase-app.js');
importScripts('/bower_components/firebase/firebase-messaging.js');

firebase.initializeApp({
'messagingSenderId': ''
});

var messaging = firebase.messaging();

messaging.setBackgroundMessageHandler(function(payload) {
console.log('[firebase-messaging-sw.js] Received background message ', payload);

var notificationTitle = payload.notification.title;
var notificationOptions = {
body: payload.notification.body,
icon: '../images/fresh/android/android-launchericon-24-24.png'
};
return self.registration.showNotification(notificationTitle,
notificationOptions);
});

Manifest.json includes "gcm_sender_id": "103953800507",

Request help to resolve the issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants