最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Notification.requestPermissions - no dialog shown, "automatically blocked" message in Chrome - St

programmeradmin2浏览0评论

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":

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?

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":

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?

Share Improve this question edited Sep 24, 2020 at 18:48 Alex from Jitbit asked Sep 18, 2020 at 10:43 Alex from JitbitAlex from Jitbit 61.2k19 gold badges208 silver badges174 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

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

That little lock icon in the address bar - is the new "notification prompt" ladies and gentlemen.

That's... disappointing

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论