如何接收和处理Chromenotifications/push-notification?
How to receive and handle Chrome notifications/push-notification?
我只想编写一个小脚本,每当我收到来自浏览器的推送通知时执行 Foo() (chrome)。我试图在那里找到一些东西,但我发现的只是如何发送上述通知,但我只想接收它们。谁能指引我正确的方向?
- 我不拥有发送通知的后端
- 没有前端,来自浏览器的通知
- 我目前正在尝试使用浏览器扩展程序,但无法访问通知。我不知道浏览器扩展是否可行,从我最初的 post.
应该很清楚
如果问题是关于拦截网页上使用 Notification API, this answer explains how:
生成的通知
总而言之,它包括创建一个 Proxy
作为本机 Notification
的包装器,以便挂接到其 constructor
并执行任意代码。
如果问题是关于拦截Push Notifications then it is impossible because they are based on the Service worker。你不能连接到服务工作者,你不能注册你自己的服务工作者而不覆盖现有的服务工作者(这会破坏网页),如文档中所述:
If there is an existing service worker available, the new version is
installed in the background, but not yet activated — at this point it
is called the worker in waiting. It is only activated when there are
no longer any pages loaded that are still using the old service
worker. As soon as there are no more pages to be loaded, the new
service worker activates (becoming the active worker).
我只想编写一个小脚本,每当我收到来自浏览器的推送通知时执行 Foo() (chrome)。我试图在那里找到一些东西,但我发现的只是如何发送上述通知,但我只想接收它们。谁能指引我正确的方向?
- 我不拥有发送通知的后端
- 没有前端,来自浏览器的通知
- 我目前正在尝试使用浏览器扩展程序,但无法访问通知。我不知道浏览器扩展是否可行,从我最初的 post. 应该很清楚
如果问题是关于拦截网页上使用 Notification API, this answer explains how:
总而言之,它包括创建一个 Proxy
作为本机 Notification
的包装器,以便挂接到其 constructor
并执行任意代码。
如果问题是关于拦截Push Notifications then it is impossible because they are based on the Service worker。你不能连接到服务工作者,你不能注册你自己的服务工作者而不覆盖现有的服务工作者(这会破坏网页),如文档中所述:
If there is an existing service worker available, the new version is installed in the background, but not yet activated — at this point it is called the worker in waiting. It is only activated when there are no longer any pages loaded that are still using the old service worker. As soon as there are no more pages to be loaded, the new service worker activates (becoming the active worker).