Notifications while browser is closed

爱⌒轻易说出口 提交于 2019-12-12 09:56:41

问题


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!


回答1:


In Chrome extensions, you have 2 tools at your disposal:

  1. 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.

  2. "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.

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).



来源:https://stackoverflow.com/questions/39247422/notifications-while-browser-is-closed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!