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

Not working in chrome #126

Closed ak868308 closed 6 years ago

ak868308 commented 7 years ago

Hi All, I don't know whats wrong with me. Push.js is working fine in mozilla for both (desktop/mobile) but not working for chrome while on desktop chrome it is working like a charm but for mobile chrome it never shows an error & not a notification. Here is my code:

Push.config({serviceWorker: '/js/alerts/serviceWorker.min.js'}); Push.create('XYZ is online', { body: 'You can contact him now', icon: '/images/logo.png', link: '#', requireInteraction: false, tag: 'online-alert', vibrate: [200, 100] }).catch(function(e) { console.log(e); });

Please help if there is any fix Thanks

Nickersoft commented 7 years ago

Is your site HTTPs? Mobile Chrome requires service workers to show notifications properly, and will only allow notifications that are SSL-encrypted (begin with https:// not http://). It should theoretically work on http:// sites in any other browser, just not Mobile Chrome.

k0t0fey commented 7 years ago

Have the same problem. And yes, my site https. I generally do not understand how the button works on the demo page in mobile chrome. Full cloning of this page does not work. In addition, there is no code on the demo page that connects the serviceWorker... My clone of demo page: https://shikari.do/push.html

Nickersoft commented 7 years ago

@k0t0fey I ran your site on my phone and checked Chrome's inspector and saw the following error:

TypeError: Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script.

From the sounds of things, it can't find any service worker. The most common fix for this is specifying a custom path to the service worker via the serviceWorker config option. See the bottom of this page for more info on this.

k0t0fey commented 7 years ago

Finally, it worked only after I placed the minified service worker file in the root of the my site. If specify a different path through the settings (Push.config), it does not work.

Nickersoft commented 7 years ago

@k0t0fey I think this might have to do with the scoping issue mentioned in #87. However, that problem was discussed before v1.0 and before the serviceWorker config option was available, so perhaps the config option isn't working? Could you shed some light on which paths you were passing to the option, the path you're calling Push from, and any errors that are being thrown?

mikeshow commented 7 years ago

Hi,

In Chrome 62 I get that error:

Uncaught (in promise) PushError: permission request declined

In Chrome Canary 64, IE, Edge, Fiefox, Opera it works.

Mike.

I forgot: I tested on https://pushjs.org/

PS: after implementing it, it works in Chrome 62 but not with pushjs.org.

ak868308 commented 7 years ago

@mikeshow please place your serviceWorker.js in web/ director. Means in a root directory.

1Rhino commented 6 years ago

Me too. Chrome Version 62.0.3202.75 (Official Build) (64-bit) - MacOS 10.12.6 Error: Uncaught (in promise) PushError: permission request declined serviceWorker.js was included.

Firefox, Safari worked :(

imRohan commented 6 years ago

Same here.

I placed serviceWorker.js in the root and I'm still getting an

Uncaught (in promise) PushError: permission request declined.

It's in the same folder as index.html

Works in Firefox, Safari

Nickersoft commented 6 years ago

Guys, I finally got a chance to look at this issue. I'm using Chrome 62.0.3202.89 on Windows 10 and the demo on pushjs.org works just fine. Are you sure you didn't accidentally deny permission for the entire webpage? If you click in the green area next to the URL, you can select whether to always allow or always deny permissions for that page. If it's set to deny, this error may occur. I would check your browser settings.

izll commented 6 years ago

https://www.chromestatus.com/feature/5759967025954816 In chrome 62 the insecure usage of notifications removed :(

Nickersoft commented 6 years ago

@izll I think that would explain a lot

projct1 commented 6 years ago

Same issue with Version 62.0.3202.94 (Official Build) 64 bit Windows 10. http://joxi.ru/l2ZVP4EH8GyWR2 http://joxi.ru/a2XeBzEUyok57A

theLufenk commented 6 years ago

Notification permission cannot be granted to an insecure origin (expect localhost) in Chrome. This doesn't seem like a bug in Push.js by itself. Closing.

amanprofsys commented 2 years ago

Hi @Nickersoft , you made a great liberary for sure and i respect your work but can you help me i am not able to use this notification on android smartphones. Please help. Thanks.