题目描述
需求是监听浏览器通知接口,以处理相应操作。
题目来源及自己的思路
重写该方法,但受限!启动另一个Worker仅允许在页面上下文中,且该站点限制脚本注入。
相关代码
Notification.requestPermission(perm =>
(navigator.serviceWorker.ready.then(reg => {
reg.__proto__.showNotification = ()=>{
console.log('通知');
reg.__proto__.showNotification(arguments)
};
})
)
你期待的结果是什么?实际看到的错误信息又是什么?
Print the log.