65

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:

  • 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?

Thanks for reading.

4

2 に答える 2

83

Web ページがアクティブでない場合でも、Service Workers、Service Worker の通知 API、およびサーバー起動通知 (またはスケジュールされた通知) のプッシュ APIを使用して、プッシュ通知を送信できます。

2016 年 6 月の時点で、Service Worker は Chrome、Firefox、Opera でサポートされています。https://jakearchibald.github.io/isserviceworkerready/でステータスを参照してください。

関連する議論、実装状況、および仕様については、次のリンクを参照してください。

于 2014-12-02T18:12:50.543 に答える
0

W3C Push APIを使用して、探していることを正確に行うことができます。

すべてをゼロから構築したい場合は、Google によるこのチュートリアルを読み始めることをお勧めします。これは Chrome 用ですが、Firefoxも非常によく似た方法で動作します。

しかし、それは大変な作業であり、「標準」はまだ発展途上です。Pushpadのようなサービスを使用することをお勧めします(私は創設者です)。

于 2016-03-21T11:28:14.877 に答える