在 Chrome 或 Firefox 中从关闭的网络应用程序发送桌面通知? [英] Send desktop notifications in Chrome or Firefox from a closed web app?

查看:23
本文介绍了在 Chrome 或 Firefox 中从关闭的网络应用程序发送桌面通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是在 Chrome 中发送Gmail 风格的桌面通知或来自当前未在浏览器中打开的 Web 应用程序(我们称之为 X)的 Firefox,无需用户安装应用程序或扩展程序.如果用户需要授予从 X 接收通知的权限就可以了,如果需要打开浏览器才能显示通知也可以,只要 X 不需要在浏览器中打开即可.不需要打开任何浏览器窗口的解决方案也适用.

My goal is to send Gmail-style desktop notifications in Chrome or Firefox from a web app (let's call it X) that is NOT currently open in the browser, without requiring the user to install an app or extension. It's okay if the user needs to grant permission to receive notifications from X, and it's okay if the browser needs to be open for the notification to appear, as long as X doesn't need to be open in the browser. A solution that doesn't require any browser window to be open would also work.

我刚刚花了一天时间深入研究这个问题,到目前为止我认为我已经学会了:

I just spent the day digging into this, and so far I think I've learned:

  • 从 OSX Mavericks 开始,可以通过 Safari 在 Safari 7+ 中执行此操作推送通知.
  • 网络通知 API 适用于 Chrome/Firefox,但要求用户的浏览器对 X 开放.
  • Twitter 无需询问用户首先获得许可,但需要用户的浏览器打开 Twitter.
  • 有很多可能的参考Growl 实现,但据我所知,所有这些实现都需要用户安装 Growl 和/或支持 Growl 的应用才能工作.
  • Since OSX Mavericks, it has been possible to do this in Safari 7+ via Safari Push Notifications.
  • The Web Notifications API works in Chrome/Firefox, but requires the user's browser to be open to X.
  • Twitter sends similar web notifications without asking the user for permission first, but requires the user's browser to be open to Twitter.
  • There are lots of references to possible Growl implementations, but as far as I can tell, all of them require the user to install Growl and/or a Growl-enabled app to work.

我上面的任何陈述都可能是错误的 - 我很想听听!- 我也愿意接受任何其他解决方案.有什么想法吗?

I could be wrong about any of my statements above - I'd love to hear it! - and I'm open to any other solution too. Any ideas?

感谢阅读.

推荐答案

即使您的网页未处于活动状态,您也可以使用 Service WorkersService Workers 的通知 APIpush API 用于服务器发起的通知(或 预定通知).

You can send push notifications even when your web page is not active using Service Workers, the Notification API for service workers and the push API for server-initiated notifications (or scheduled notifications).

截至 2016 年 6 月,Chrome、Firefox 和 Opera 支持 Service Worker.在 https://jakearchibald.github.io/isserviceworkerready/

As of June 2016, Service Workers are supported in Chrome, Firefox and Opera. See the status at https://jakearchibald.github.io/isserviceworkerready/

有关相关讨论、实施状态和规范,请参阅以下链接.

See the following links for related discussions, status of implementation and specifications.

  • Service workers are enabled by default since Chrome 40, Firefox 33, and Opera 24. See the HTML5Rocks tutorial and MDN.
  • Push notifications: Chrome 42+, Firefox 44+

这篇关于在 Chrome 或 Firefox 中从关闭的网络应用程序发送桌面通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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