在 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 策略:
1let shaking = false
2setInterval(() => {
3 if (shaking) document.title = `[Notification] ${word}!!`
4 else document.title = word
5 shaking = !shaking
6}, 200)
7
但是实测效果还是不够显眼,最终在和群友的交流之后,发现了 chrome://flags/ 。
Insecure origins treated as secure
中填写需要开启 Notification API 的域名,重启浏览器,就可以在 HTTP 中使用 Notification API 了。