如何监听ServiceWorkerRegistration.showNotification在serviceWorker线程中~

题目描述

需求是监听浏览器通知接口,以处理相应操作。

题目来源及自己的思路

重写该方法,但受限!启动另一个Worker仅允许在页面上下文中,且该站点限制脚本注入。

相关代码

Notification.requestPermission(perm =>

(navigator.serviceWorker.ready.then(reg => {
  reg.__proto__.showNotification = ()=>{
    console.log('通知');
    reg.__proto__.showNotification(arguments)
  };
})

)

你期待的结果是什么?实际看到的错误信息又是什么?

Print the log.

阅读 826
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题