在 HTTP 网站中开启 Notification API

Notification API 只能在 HTTPS 中使用:Using the Notifications API

This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

但是在开发某游戏网站脚本的时候,虽然它用的是 HTTP,但是仍然想用 Notificition 做一下提醒功能,当然,可以降级成过去 800 年的闪 Title 策略:

let shaking = false
setInterval(() => {
    if (shaking) document.title = `[Notification] ${word}!!`
    else document.title = word
    shaking = !shaking
}, 200)

但是实测效果还是不够显眼,最终在和群友的交流之后,发现了 <chrome://flags/> 。

Insecure origins treated as secure 中填写需要开启 Notification API 的域名,重启浏览器,就可以在 HTTP 中使用 Notification API 了。

植入部分

如果您觉得文章不错,可以通过赞助支持我。

如果您不希望打赏,也可以通过关闭广告屏蔽插件的形式帮助网站运作。

标签: 知识

仅有一条评论

  1. 阿冰

    没错,在下就是那个群友

添加新评论