【发布时间】:2015-06-28 18:27:51
【问题描述】:
我的网站使用从未在移动设备上运行过的桌面通知,但我最近开始在 Android 4.4 上的 Chrome 版本 42.0.2311.108 中收到以下异常:
Failed to construct 'Notification': Illegal constructor. Use ServiceWorkerRegistration.showNotification() instead. TypeError: Failed to construct 'Notification': Illegal constructor. Use ServiceWorkerRegistration.showNotification() instead.
我的通知代码很简单,在检查用户是否授予权限后,我初始化一个新的通知对象,如下所示:
var notification = new Notification(messageOptions.title, { icon: messageOptions.icon });
如何更改此代码以使用显示为 undefined 的 ServiceWorkerRegistration.showNotification 来支持移动版 Chrome 中的通知,或者如果无法执行功能检测并防止发生异常如果 [还] 确实不支持。
【问题讨论】:
-
我只是把这个放在一起,这对你有用吗? jsbin.com/rexede/latest/quiet
-
与您的示例相同的错误消息。在桌面 chrome 上工作正常,但在 android 上失败。 Android 5.1.0 上的 Chrome 42.0.2311.109; Nexus 5 构建/LMY47I
标签: javascript android google-chrome mobile html5-notifications