我想在 chrome 浏览器上收听 google、facebook、whatsapp 等网站的传入通知。我看到这里提到的黑客不再有效,因为webkitNotifications.createNotification
已被弃用。一些网站使用劳务工,所以我不知道如果我可以用这样webAPIs ServiceWorkerRegistration.getNotifications()
,PushManager
,ServiceWorkerGlobalScope
甚至是Notification
API?我一直在阅读,找不到任何东西可以做到这一点。我也不介意黑客攻击。使用硒可以做任何事情吗?有可能吗?如果没有,我不会在上面浪费更多时间。干杯!
注意:我正在寻找一种解决方案,我可以在其中收听其他网站上的通知,而不是我的。
javascript google-chrome push-notification selenium-webdriver
我想拦截HTML5 Web通知。我已经阅读了以下答案,其中用户建议可以window.Notification
用您自己的充当代理的对象覆盖该对象。我试图这样做,但是无法使其正常工作。以下是页面加载后我要注入的JavaScript代码:
function setNotificationCallback(callback) {
const OldNotify = window.Notification;
OldNotify.requestPermission();
const newNotify = (title, opt) => {
callback(title, opt);
return new OldNotify(title, opt);
};
newNotify.requestPermission = OldNotify.requestPermission.bind(OldNotify);
Object.defineProperty(newNotify, 'permission', {
get: () => {
return OldNotify.permission;
}
});
window.Notification = newNotify;
}
function notifyCallback(title, opt) {
console.log("title", title); // this never gets called
}
window.Notification.requestPermission(function (permission) {
if (permission === "granted") {
setNotificationCallback(notifyCallback);
}
})
Run Code Online (Sandbox Code Playgroud)