Skip to content
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

Registration failed - push service error #2475

Closed
pgedzba opened this issue May 25, 2020 · 7 comments
Closed

Registration failed - push service error #2475

pgedzba opened this issue May 25, 2020 · 7 comments

Comments

@pgedzba
Copy link

pgedzba commented May 25, 2020

Version info

**Angular:**9.1.9

**Firebase:**7.14.4

**AngularFire:**6.0.0

**Other (e.g. Ionic/Cordova, Node, browser, operating system):**Brave/Chrome

How to reproduce these conditions

After logging in I am calling this function:
image
It returns an error on line 57, which is described below. If I remove requestToken and change it to requestPermission then there is no error, but I am not receiving any messages.

I have VAPID key from firebase cloud messaging.

Below is full messaging.service.ts
`
@Injectable()
export class MessagingService {

currentMessage = new BehaviorSubject(null);

constructor(
    private angularFireDB: AngularFireDatabase,
    private angularFireAuth: AngularFireAuth,
    private angularFireMessaging: AngularFireMessaging,
    private httpClient: HttpClient) {
    this.angularFireMessaging.usePublicVapidKey(environment.VAPID_KEY);
    // this.angularFireMessaging.messaging.subscribe(
    //     (_messaging) => {
    //         _messaging.onMessage = _messaging.onMessage.bind(_messaging);
    //         _messaging.onTokenRefresh = _messaging.onTokenRefresh.bind(_messaging);
    //     }
    // );
}

/**
 * update token in firebase database
 *
 * @param userId userId as a key
 * @param token token as a value
 */
updateToken(userId, token) {
    // we can change this function to request our backend service
    this.angularFireAuth.authState.pipe(take(1)).subscribe(
        () => {
            const data = {};
            data[userId] = token;
            this.httpClient.post(environment.API_URL + '/api/device_tokens', { token }).subscribe();
            this.angularFireDB.object('fcmTokens/').update(data);
        });
}

/**
 * request permission for notification from firebase cloud messaging
 * 
 * @param userId userId
 */
requestPermission(userId) {
    this.angularFireMessaging.requestToken.subscribe(
        (token) => {
            this.updateToken(userId, token);
        },
        (err) => {
            console.error('Unable to get permission to notify.', err);
        }
    );
}

/**
 * hook method when new notification received in foreground
 */
receiveMessage() {
    this.angularFireMessaging.messages.subscribe(
        (payload) => {
            this.currentMessage.next(payload);
        });
}

}
`

Debug output

** Errors in the JavaScript console **
messaging.service.ts:57 Unable to get permission to notify. DOMException: Registration failed - push service error

image

Expected behavior

Notifications should register

Actual behavior

I get an error

@naveedahmed1
Copy link

Any update on this?

@pgedzba
Copy link
Author

pgedzba commented Jun 4, 2020

I didn't find the solution yet

@naveedahmed1
Copy link

Its strange that its working on some devices and throwing this error on other devices.

@naveedahmed1
Copy link

@pgedzba can you please check if it's working on Firefox on same machine? In my case it's working fine on Firefox but throwing error in Chrome.

@pgedzba
Copy link
Author

pgedzba commented Jun 11, 2020

I can not install any other browser on this machine

@shadow1349
Copy link

shadow1349 commented Oct 18, 2020

I've been having a similar problem specifically on Brave:

push service error

This one has been particularly annoying because I can't use any of my callable functions on Brave without getting this exact same error which is just plain weird.

I can say this is not reproducible on FireFox.

@jamesdaniels
Copy link
Member

Closing here in favor of the js sdk bug, as it's not AngularFire specific.

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

No branches or pull requests

4 participants