Skip to content
Advertisement

Notification.requestPermissions – no dialog shown, “automatically blocked” message in Chrome

I’m testing HTML5 notifications on localhost, with SSL. I’ve reset the Chrome settings for the site (by clicking the lock icon in the URL box – “site settings”), and double checked notification setting is set to “Ask (default)”.

Now here’s my code:

if (Notification.permission !== "granted") {
    Notification.requestPermission();
}

But once the code is run, no permissions popup is displayed, instead I get this lock icon in the address bar that says “Notifications blocked”:

enter image description here

Tried adding .then() promise to the code – same result. Using Chrome Version 85.0.4183.102. Did they change something?

I do see blog posts mentioning that Chrome disables notifications automatically if the user closed the popup three times, But I did reset the settings did I?

P.S. If I refresh the page and request the permissions again – I see this in the console "Notifications permission has been blocked as the user has ignored the permission prompt several times." Wait, how could I ignore the prompt if I haven’t even seen it?

Advertisement

Answer

Ok, so after an hour of banging my head against the wall, I found the reason.

enter image description here

That little lock icon in the address bar – is the new “notification prompt” ladies and gentlemen.

I’m trying to keep my calm here, but… FFS Google are you serious?

P.S. We all understand the intention behind this is to prevent people from abusing these popups. But a better way would be to check, if the code runs in the user-triggered context (e.g. in response to a click) and if so – leave it like before.

Advertisement