Nickersoft / push.js

The world's most versatile desktop notifications framework :earth_americas:
https://pushjs.org
MIT License
8.76k stars 548 forks source link

Chrome on Android - opening window does not work #132

Closed felixhagspiel closed 6 years ago

felixhagspiel commented 6 years ago

Hello, first thanks for your great work!

Currently I am facing an issue where notifications are displayed on Chrome/Android, but on notification click nothing happens (error on console).

When I inspect my mobile device via chrome dev tools & click the notification, I get the error:

VM29:2 Uncaught ReferenceError: e is not defined at eval (eval at runFunctionString (serviceWorker.min.js:1), <anonymous>:2:14) at runFunctionString (serviceWorker.min.js:1) at self.onnotificationclick (serviceWorker.min.js:1)

My site is running on HTTPS and I am using version 1.0.5.

This is how I create the notification (I am using reactJS):

PushJS.create('My fancy title', {
                      body: 'My fancy notification text',
                      requireInteraction: true,
                      onClick: function(){
                        if(window) {
                          // focus window
                          window.focus();
                          // close notification on click
                          this.close();
                          let nextRoute: T.TReactRoute = {
                            state: {
                              prevRoute: window.location.pathname
                            },
                            pathname: R.contracts.routes.detail.getRoute(data.contractCode)
                          };

                          browserHistory.push(nextRoute);
                          console.log(pushNotification)
                        }
                      }
                    });

Chrome on Mac / Desktop is working fine. Am I missing something here?

LKaemmerling commented 6 years ago

@felixhagspiel i have the same issue, what was your solution?

felixhagspiel commented 6 years ago

@LKDevelopment as far as I see it, in order to be able to correctly use it on android you have to register your app on google to allow the service worker to run in background. It only works on desktop when the apps tab is open. You can check the google tutorial: https://developers.google.com/web/fundamentals/codelabs/push-notifications/

I have not tried this yet, as we have more important things to solve atm. For now I disabled push notifications on android.