Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chrome Web Push support #6697

Open
jasonpang opened this issue Aug 2, 2016 · 36 comments
Open

Chrome Web Push support #6697

jasonpang opened this issue Aug 2, 2016 · 36 comments

Comments

@jasonpang
Copy link

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?

@kevinsawicki kevinsawicki changed the title Chrome Web Push Support? Chrome Web Push support Aug 8, 2016
@raztd
Copy link

raztd commented Aug 10, 2016

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

@anaisbetts
Copy link
Contributor

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)

@biiiipy
Copy link

biiiipy commented Nov 2, 2016

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.

@anaisbetts
Copy link
Contributor

@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

@zcbenz
Copy link
Contributor

zcbenz commented Nov 16, 2016

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.

@janekolszak
Copy link

Has anything changed?

@jamesmfriedman
Copy link

jamesmfriedman commented Feb 8, 2017

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

@ericbets
Copy link

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

@mirzadelic
Copy link

+1, need this too.

@Praggie
Copy link

Praggie commented Apr 11, 2017

+1, this is really a needed feature.

@ghost
Copy link

ghost commented May 3, 2017

+1, would be awesome to add this.

@rhysd
Copy link
Contributor

rhysd commented May 3, 2017

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

@zoonman
Copy link

zoonman commented Jun 30, 2017

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?

@caleboau2012
Copy link

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

@zoonman
Copy link

zoonman commented Jul 6, 2017

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

@jamesmfriedman
Copy link

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

@caleboau2012
Copy link

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)

@jamesmfriedman
Copy link

jamesmfriedman commented Jul 6, 2017 via email

@ericbets
Copy link

ericbets commented Jul 6, 2017

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.

@jamesmfriedman
Copy link

jamesmfriedman commented Jul 6, 2017 via email

@zoonman
Copy link

zoonman commented Jul 7, 2017

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

@jamesmfriedman
Copy link

jamesmfriedman commented Jul 7, 2017

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

@zoonman
Copy link

zoonman commented Jul 7, 2017

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

@jamesmfriedman
Copy link

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.

@MatthieuLemoine
Copy link

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

@ccorcos
Copy link

ccorcos commented Aug 2, 2017

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.

@jamesmfriedman
Copy link

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

@magne4000
Copy link
Contributor

@jamesmfriedman have you found a workaround for this ?

@MatthieuLemoine
Copy link

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.

@jkleinsc
Copy link
Member

jkleinsc commented Nov 2, 2017

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

@burtonator
Copy link

@MatthieuLemoine Thanks for doing this. Saw your post and I'll be playing with it here soon. Almost a year later but better late than never of course.

I can't believe this is still an issue though.

@eladnava
Copy link

eladnava commented Dec 3, 2019

For anyone still interested, Pushy has just released an open source package for sending push notifications to Electron apps using a background MQTT connection:
pushy-me/pushy-electron

Full disclosure: I work for Pushy.

@rthomascafex
Copy link

For what it's worth, I don't think running on startup is an issue that needs to be solved by electron as such. Chrome starts a service in the background at startup if it is requested to do so, but I've noticed that Firefox doesn't. I think it would be completely acceptable to just poll for push notifications during electron's run time and then that would seem to mirror Firefox's behaviour.

@quetzalcoatl
Copy link

Issue is still present in the recent Electron version:

Node.js 12.8.1, Chromium 78.0.3904.130, and Electron 7.1.7

I tried integrating Firebase Cloud Messaging and it finally failed on "obtaining an FCM token" step with following error message:

Registration failed - push service not available

Pretty obvious that it's about {this} issue.

MatthieuLemoine's solution from https://github.com/MatthieuLemoine/electron-push-receiver was easy to integrate and works like a charm. Thanks, Matthieu!

@cottons-kr
Copy link

any progress? I really need this

@tavrez
Copy link

tavrez commented Aug 21, 2024

With the Apple ecosystem supporting the Web Push API, PWAs now have a huge advantage over Electron-based apps.

It is really necessary to implement a way to support push messaging globally in Electron—not necessarily through the Web Push API, but by using OS-native push support (Apple has the Notifications API, Windows also has push notifications through the Windows App SDK, etc.).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests