electron icon indicating copy to clipboard operation
electron copied to clipboard

Chrome Web Push support

Open jasonpang opened this issue 9 years ago • 36 comments

I came across this previous issue, where it was said that Chrome Push would not be supported at the time since Google's private services are not included in Electron's content bundle. Now that Chrome 52 supports a non-proprietary protocol, would Electron eventually support web push notifications?

jasonpang avatar Aug 02 '16 21:08 jasonpang

+1 for this. Hope it will get implemented. As of today, Electron's notifications are not consistent, because native notifications aren't. On some systems they are shown on top right corner of the screen (mac os, ubuntu), some on bottom right corner (windows 10, kubuntu); on some systems they are clickable (kubuntu, mac os), on some they are not (ubuntu)

raztd avatar Aug 10 '16 19:08 raztd

This probably won't be implemented because there's a fair amount of custom UI associated with it (i.e. Chrome runs a process in the background, it puts an item in the notification area on Windows, etc etc etc)

anaisbetts avatar Aug 10 '16 22:08 anaisbetts

I think the value is in the push mechanism, not in the UI. Electron could just provide an API to execute a callback when a message is received and the app can decide what to do with the message - there's no need to implement UI in electron.

biiiipy avatar Nov 02 '16 08:11 biiiipy

@biiiipy I'm not talking about the message itself, but the UI to be able to decide whether you allow a process to run on startup:

image

At the end of the day, push notifications aren't magic, somebody is running in the background picking up the phone. Electron could plumb this into an API, but it could potentially be pretty Complicated and Not-User-Intuitive

anaisbetts avatar Nov 06 '16 02:11 anaisbetts

For people wanting a custom notification interface: we are never going to add that, we will stick to the system notifications. This issue is about possibly supporting the Web Push protocol, instead of Chrome's notification system.

zcbenz avatar Nov 16 '16 08:11 zcbenz

Has anything changed?

janekolszak avatar Jan 17 '17 19:01 janekolszak

I'm new to Electron so I can't say I quite understand all of the platform differences: however since the standardization of the Push Api, isn't this a Chromium and not a Chrome specific feature?

The Chromium runtime docs show PushMessaging as a stable feature. Is it just a matter of enabling it in the electron Build? I've tried using blinkfeatures and webpreferences settings on a webview but haven't had any luck. Would be great if this was a simple flip of a switch. I'd hate to have to bail on FCM since its nicely integrated with the rest of my app.

https://cs.chromium.org/chromium/src/third_party/WebKit/Source/platform/RuntimeEnabledFeatures.in

jamesmfriedman avatar Feb 08 '17 18:02 jamesmfriedman

+1 for this. In the browser project that I'm working on (described in #8534), I'd really like to make the start page (when you start a browser or add a tab) a feed type list of your recent HTML5 notifications. For me this is much better than a modal that interrupts. It's also probably the first step in a true open source type facebook thingy. I would propose electron simply add a runInBackground attribute in BrowserWindow and let the UI decide how to handle any inbound notifications with a generic event.

ericbets avatar Feb 17 '17 19:02 ericbets

+1, need this too.

mirzadelic avatar Apr 03 '17 17:04 mirzadelic

+1, this is really a needed feature.

Praggie avatar Apr 11 '17 01:04 Praggie

+1, would be awesome to add this.

ghost avatar May 03 '17 15:05 ghost

In my application, some page is open with<webview>. And the page shows notifications with web push. I want to utilize the page's notification as desktop notification. I understood that this issue should be solved for this...

rhysd avatar May 03 '17 22:05 rhysd

Will there be a way to configure your own push notification service? It will be useful for completely closed (disconnected from Internet) corporate networks. I know, it is possible to do with Firefox. What is about Electron?

zoonman avatar Jun 30 '17 14:06 zoonman

@zoonman is there any service we can use already?

As this issue is still open, can I assume push notifications to electron (not the UI bit but the push from the server to the client) is still not possible?

caleboau2012 avatar Jul 06 '17 18:07 caleboau2012

@caleboau2012 as I know it is not available for now. But, because electron has a node process running all the time, you can hook it up to something like Firebase and use it a as transport layer. And send notifications using regular Notifications API.

zoonman avatar Jul 06 '17 19:07 zoonman

I read back through this thread, and it really does seem like every other person is talking about a different thing. I just wanted to clear something up for future readers. People are requesting these two separate but related things:

  1. Background Push Notifications - people looking for a way to push a basic notification to the app when it is not open, resulting in a Chrome Notification, or desktop comparable notification. Something like "You have 2 new messages".

  2. Background Push API - This is a way for the client to receive messages and data even when the app is closed. This can result in a notification, but doesn't have to. My interest in this feature was to use it like a phone app and alert a user of incoming calls. Google Chrome uses GCM (Google Cloud Messaging) to achieve push messaging is built into the browser by default, here is a link to the spec: https://developer.mozilla.org/en-US/docs/Web/API/Push_API

For the Electron team, What I still don't understand on point #2 is that Node-Webkit has been able to enable this. You should be able to build Electron with it enabled as it doesn't appear that NW did anything special to achieve this other than turning on a flag and providing the same global API key for GCM that Chrome does.

It was a bummer on my last project because I was using Firebase Cloud Messaging which relies on the push spec, and was forced to go with NodeWebkit even though I definitely wanted to use Electron ;).

jamesmfriedman avatar Jul 06 '17 21:07 jamesmfriedman

Thanks @jamesmfriedman. #2 is a more pertinent issue to me. Are you implying that there is no workaround like @zoonman suggested.

@zoonman, if there is, can you share a link to any helpful guides for hooking electron up to firebase (using it as a transport layer)

caleboau2012 avatar Jul 06 '17 22:07 caleboau2012

The workaround he's talking about definitely won't work with Firebase Cloud Messaging since it requires the browsers Push Api. You could only use it for your own home rolled notifications service.

Sent from my iPhone

On Jul 6, 2017, at 6:02 PM, Mbakwe Caleb [email protected] wrote:

Thanks @jamesmfriedman. #2 is a more pertinent issue to me. Are you implying that there is no workaround like @zoonman suggested.

@zoonman, if there is, can you share a link to any helpful guides for hooking electron up to firebase (using it as a transport layer)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

jamesmfriedman avatar Jul 06 '17 22:07 jamesmfriedman

ServiceWorker.prototype.showNotification and window.PushManager are both override-able. I just checked. So theoretically people could inject their own impls of this svc in their webviews and it should all just work.

ericbets avatar Jul 06 '17 22:07 ericbets

Yep, went down that path. Also not doable since there's nothing you can override it with that's going to work when the client is closed.

Sent from my iPhone

On Jul 6, 2017, at 6:42 PM, ericbets [email protected] wrote:

ServiceWorker.prototype.showNotification and window.PushManager are both override-able. I just checked. So theoretically people could inject their own impls of this svc in their webviews and it should all just work.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

jamesmfriedman avatar Jul 06 '17 22:07 jamesmfriedman

@caleboau2012 you will need to start here https://github.com/firebase/quickstart-nodejs It shows how to connect to firebase using Node.js. After, you will have to follow this guide to listen for changes on value https://firebase.google.com/docs/database/web/read-and-write#listen_for_value_events

Basically you will need to implement broacaster-observer pattern. You will need a separate app which will be server and it will be responsible for broadcasting messages. On Electron side you will subscribe for changes on object. For example, your database will have structure like this /user/:userId/notifications. Electron will subscribe to listen on it and wait when change will appear, after you will display notification within Electron.

If you think that work with Firebase is too complicated, you can use server-side websockets to communicate between Electron app and your server.

zoonman avatar Jul 07 '17 00:07 zoonman

@zoonman there are absolutely other ways you can receive messages in the background, what you're referencing in your post is the Firebase Database. Firebase is a conglomeration of services, the particular one I was talking about is Firebase Cloud Messaging https://firebase.google.com/docs/cloud-messaging/. But none of this is about Firebase...

Sure, you can find a work around way to receive background notifications and data with Electron, but there is a built in browser Push api that is supported in official Chrome and Node Webkit, and Electron just doesn't appear to be enabling it in its Chromium build.

jamesmfriedman avatar Jul 07 '17 01:07 jamesmfriedman

@jamesmfriedman you are correct, Firebase is not the best choice here. Also, "Cloud Messaging" is based upon PushManager.

Anyway, Electron app must be running in order to establish connection to server side. Either way you must have some sort of continuously running daemon responsible for retrieving notifications. The perfect example is APNS, where this role has played by OS itself.

And I agree that builtin browser Push API must be exposed alongside with its settings.

zoonman avatar Jul 07 '17 15:07 zoonman

Yeah @zoonman, spot on. I actually don't know how Chrome handles this for its ServiceWorkers when it's closed, but there is for sure something listening for incoming push messages. I don't know what is different about Node Webkit, but it does "just work" without any additional configuration, other than a flag to enable Google cloud messaging http://docs.nwjs.io/en/latest/References/Command%20Line%20Options/#-enable-gcm.

jamesmfriedman avatar Jul 07 '17 15:07 jamesmfriedman

@jamesmfriedman The difference with nw.js is that electron is based on Chromium Content using libchromiumcontent and not on the whole Chromium browser.

To enable Push Notifications support, the browser needs to maintain an active connection to a push service in order to receive push messages as long as it is open.

Unfortunately, the integration with a push service (FCM for chromium/chrome) is not part of the Content API.

Therefore if you try to run :

serviceWorkerRegistration.pushManager.subscribe()

it will raise :

AbortError: Registration failed - push service not available

You can reproduce it using Content Shell which is a basic browser built on top of the Content API.

MatthieuLemoine avatar Aug 01 '17 22:08 MatthieuLemoine

This might be a little off-topic, but would it be possible to integrate directly with the Mac Push Notification API? For Mac, we at least wouldn't need any background processes running and the OS will handle everything for us.

ccorcos avatar Aug 02 '17 02:08 ccorcos

@MatthieuLemoine thank you so much!!! All I wanted to know was why, it was driving me crazy. At least now that I know the limitation I can work around it.

jamesmfriedman avatar Aug 02 '17 13:08 jamesmfriedman

@jamesmfriedman have you found a workaround for this ?

magne4000 avatar Aug 23 '17 10:08 magne4000

I created a Push notification client named push-receiver to be able to receive Web Push notification in Node & Electron like Chrome does.

There's also an electron wrapper named electron-push-receiver.

If you're interested in the How does it work ?, you can read this blog post on Medium.

I'm looking for contributors that would be willing to try it and work on it.

MatthieuLemoine avatar Oct 30 '17 16:10 MatthieuLemoine

@MathieuDebit thanks for your work! It looks promising! I'll try it out!

jkleinsc avatar Nov 02 '17 14:11 jkleinsc