admin管理员组

文章数量:1201803

I have a web notification script which works fine. However when i was testing in chrome version 43, I get the error "DOMException: Registration failed - permission denied". This error occurs during the subscription stage.

Here's the code snippet which is the usual process of registration

navigator.serviceWorker.register('sw.js').then(function(reg) {
    console.log('[ServiceWorker] Registration Obj', reg);
    reg.pushManager.subscribe({
        userVisibleOnly: true
    }).then(function(sub) {
        //This never executes and catch gets called
        console.log('Subscription successful, Subscription endpoint:', sub.endpoint);
    }).catch(function(error) {
        console.log("Error during subscription ", error);
    });
}).catch(function(error) {
    if (Notification.permission === 'denied') {
        console.warn('Permission for Notifications was denied');
    } else {
        console.error('Unable to subscribe to push.', error);
    }
});

In the above code, the error occurs during the step where i do reg.pushManager.subscribe().

  • This doesn't happen in chrome 49.
  • This error always occurs on chrome version 43.

[Note] I assumed its a general problem with chrome version 43 but when i checked sites like goroost and pushcrew, they seem to be working fine. Only mine is not working

I have a web notification script which works fine. However when i was testing in chrome version 43, I get the error "DOMException: Registration failed - permission denied". This error occurs during the subscription stage.

Here's the code snippet which is the usual process of registration

navigator.serviceWorker.register('sw.js').then(function(reg) {
    console.log('[ServiceWorker] Registration Obj', reg);
    reg.pushManager.subscribe({
        userVisibleOnly: true
    }).then(function(sub) {
        //This never executes and catch gets called
        console.log('Subscription successful, Subscription endpoint:', sub.endpoint);
    }).catch(function(error) {
        console.log("Error during subscription ", error);
    });
}).catch(function(error) {
    if (Notification.permission === 'denied') {
        console.warn('Permission for Notifications was denied');
    } else {
        console.error('Unable to subscribe to push.', error);
    }
});

In the above code, the error occurs during the step where i do reg.pushManager.subscribe().

  • This doesn't happen in chrome 49.
  • This error always occurs on chrome version 43.

[Note] I assumed its a general problem with chrome version 43 but when i checked sites like goroost.com and pushcrew, they seem to be working fine. Only mine is not working

Share Improve this question edited Mar 21, 2016 at 19:08 GreenGiant 5,2361 gold badge52 silver badges81 bronze badges asked Mar 21, 2016 at 8:54 Hari KrishnanHari Krishnan 1,1662 gold badges13 silver badges32 bronze badges 4
  • Do you have a manifest linked to the page with the correct values of gcm_sender_id and gcm_user_visible_only? – Marco Castelluccio Commented Mar 21, 2016 at 10:41
  • Yes, manifest had both those fields. Also it works on other versions of chrome. – Hari Krishnan Commented Mar 21, 2016 at 11:59
  • Which of the two catch functions is being called? The last one? If so, which of the two messages gets logged? Last question, why do you need to support such an old version of Chrome? It was released nearly one year ago! – Marco Castelluccio Commented Mar 21, 2016 at 14:58
  • 1 Did you find a solution to this? – Marklar Commented Aug 5, 2016 at 7:12
Add a comment  | 

3 Answers 3

Reset to default 12

I've encountered this problem. in addition to prajnavantha answers, this may be caused by accidentally clicking the browser notification when it block it or not. To fix this in Chrome, go to Settings->click 'Show Advanced Settings'->Under 'Privacy' click 'Content Settings'->Then under 'Notifications' select 'Manage Excpetions'. Once you're in here, allow the notification for the URL affected.

I've faced a similar problem. You are particularly looking at chrome version 43.

  1. Check your manifest.json. Since you have already told that it works for a higher version, I assume that you have missed something in the manifest. In this link, Matt Gaunt suggests that this error can occur if there is a problem with the manifest.

  2. Make sure that there is no trailing comma at the end.

  3. Also, version 43 doesn't support data attribute in the notification object and doesn't allow opening a window on click on the notification, so you need to take care of these issues too.

You may also have configured chrome to block all notifications. Go to chrome://settings/content/notifications and make sure the slider is slid.

本文标签: javascriptDOMException Registration failedpermission deniedStack Overflow