0

I want to setup push notification on a web app, but I want to test it first on my local dev server (which is set with vagrant) so my local server looks something like htttp://mylocalserver.com. (I want to point out that it's really hard to change it to 127.0.0.1 because this vagrant box was made by someone else and there are also other stuff that makes it complicated to change it)

The first issue I encountered was

"Service Worker Error DOMException: Only secure origins are allowed " which i solved using the solution in "unsafely-treat-insecure-origin-as-secure" flag is not working on Chrome

But then I realized i can't use any of the Notification methods like: Notification.permission or Notification.requestPermission.

When I try to get the Notification.permission it returns "undefined". Is there a way i can make this functionality work?

Alin Faur
  • 1,091
  • 2
  • 9
  • 10

2 Answers2

0

You can't use any of the fun stuff without serving it over https, with the exception of 127.0.0.1

You could try using the chrome web server extension which will run a test server on your local machine, or set up a restricted access area on a public server secured with https.

You could also try and generate self signed certificates for your local server, but I'm not sure if chrome will play ball with those.

miknik
  • 5,748
  • 1
  • 10
  • 26
0

I found the problem in my case. The application had a model with the same name "Notification" on the window object which overrode the browser Notification.

And of course my "Notification" didn't have those methods (Notification.permission, Notification.requestPermission() ... etc) so I changed the name of the model and everything worked fine.

Alin Faur
  • 1,091
  • 2
  • 9
  • 10