浏览器关闭时的通知 [英] Notifications while browser is closed

查看:141
本文介绍了浏览器关闭时的通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Chrome扩展程序,当他访问特定页面时向用户发送通知。
我希望在浏览器关闭或在后台运行时发送通知,与智能手机类似。
任何想法或提示都会很棒!

解决方案

在Chrome扩展程序中,您可以使用两种工具: / p>


  1. chrome.gcm API ,它允许您使用Google Cloud Messaging接收推送通知。方便的是,它与Android应用使用的系统相同。您的服务器需要与GCM服务器通话以跟踪订阅并发送消息。细节超出了这个问题的范围;虽然有教程


  2. background权限,即使浏览器关闭,您的扩展程序的后台页面也可以正常工作。但是,请注意,用户可以完全禁用Chrome在后台运行,在这种情况下,您将受限于浏览器正常运行的时间(这是扩展程序正常运行的方式)。请注意,即使浏览器在发送时关闭,推送消息也会尽快发送。

  3. 您不想使用Google提供的推送工具,您可以定期轮询后台脚本的通知,也可以使用 WebSockets (如果有很多用户,它在服务器资源方面会很昂贵)。


    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:

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

    这篇关于浏览器关闭时的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆