浏览器关闭时的通知 [英] Notifications while browser is closed
问题描述
我有一个Chrome扩展程序,当他访问特定页面时向用户发送通知。
我希望在浏览器关闭或在后台运行时发送通知,与智能手机类似。
任何想法或提示都会很棒!
在Chrome扩展程序中,您可以使用两种工具: / p>
-
chrome.gcm
API ,它允许您使用Google Cloud Messaging接收推送通知。方便的是,它与Android应用使用的系统相同。您的服务器需要与GCM服务器通话以跟踪订阅并发送消息。细节超出了这个问题的范围;虽然有教程。 -
background
权限,即使浏览器关闭,您的扩展程序的后台页面也可以正常工作。但是,请注意,用户可以完全禁用Chrome在后台运行,在这种情况下,您将受限于浏览器正常运行的时间(这是扩展程序正常运行的方式)。请注意,即使浏览器在发送时关闭,推送消息也会尽快发送。 您不想使用Google提供的推送工具,您可以定期轮询后台脚本的通知,也可以使用 WebSockets (如果有很多用户,它在服务器资源方面会很昂贵)。 chrome.gcm
API, which allows you to use Google Cloud Messaging to receive push notifications. Conveniently, it's the same system Android apps use. Your server will need to talk to GCM servers to keep track of subscriptions and send the message. Details are outside the scope of this question; there's a tutorial though."background"
permission, allowing your extension's background page to work even when the browser is closed. However, note that the user can disable Chrome running in the background altogether, and in that case you'll be limited to the time the browser is normally running (which is the normal way extensions operate). Note that the push message will be delivered ASAP even if the browser was closed at the time of sending it.
I have a chrome-extension that sends notifications to the user when he visits a specific page. I wish to send the notification when the browser is closed or running in background, similar to the smartphones. Any idea or tip will be great!
In Chrome extensions, you have 2 tools at your disposal:
If you don't want to use Google-provided push tools, you can either poll regularly for notifications from a background script, or implement your own push messaging with, say, WebSockets (it's going to be expensive in terms of server resources, though, if you get many users).
这篇关于浏览器关闭时的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!