0

I'am trying to develop a desktop notification JS in my customer application. The code works fine on firefox but not on Chrome. I'm changing the notification permission to allow on settings -> Advanced -> Content Settings -> Notifications -> Allow/Deny but still not working.

this is my code :

notifyMe: function() {
    if (!("Notification" in window)) {
      alert("Ce navigateur ne supporte pas les notifications desktop");

    } else if (Notification.permission !== 'denied') {

      Notification.requestPermission(function(permission) {
        if (!('permission' in Notification)) {
          Notification.permission = permission;
        }

        if (permission === "granted") {
          var notification = new Notification("Notify ")
        }

      });
    }
}

Can somebody help me ? Thanks.

wezzy
  • 5,897
  • 3
  • 31
  • 42
servich
  • 1
  • 1

3 Answers3

1

From version 62 of chrome Notifications are supported only in secure contexts of the browser.

When is a context considered secure?

  • A context will be considered secure when it's delivered securely (or locally), and when it cannot be used to provide access to secure APIs to a context that is not secure. In practice, this means that for a page to have a secure context, it and all the pages along its parent and opener chain must have been delivered securely.
  • Locally delivered files such as http://localhost and file:// paths are considered to have been delivered securely.
  • Contexts that are not local must be served over https:// or wss:// and where the protocols used should not be considered deprecated.

For more details about the secure context read MDN Secure Contexts

And regarding support of Notification only in Secure Contexts check Browser Compatibility section of Notification

Liam
  • 27,717
  • 28
  • 128
  • 190
Rakesh Makluri
  • 647
  • 4
  • 10
0

You need a website running on HTTPS protocol when utilizing certain features such as Notification, Push Notification, service worker, geolocation, Speech to Text (using Google service), and some others. Chrome is more strict, especially in newer versions.

Muhammad Musavi
  • 2,512
  • 2
  • 22
  • 35
  • Are there any solution over plain HTTP? – servich Feb 06 '19 at 09:18
  • AFAIK there isn't. If you are using Windows IIS to host a website you can go to `IIS > Server Certificates > Create Self Signed Certificate` and then in the listed Websites in `Connections` pane select your website, after that in the right pane `(Actions)` click on `Bindings` > Add, select https type, and from `SSL Certificate` assigne the certificate you just created, now you can get access to your website through https on port 443 (Change the port if it has been reserved by another program). If your website is not running locally you can use [This](https://letsencrypt.org/getting-started/) – Muhammad Musavi Feb 06 '19 at 10:46
0
var myNotification = window.webkitNotifications.createNotification('mike.png', 'New Content Available', 'Click to view');
myNotification.onclick = function() {
    window.location = 'http://teamtreehouse.com/new/content';
}
myNotification.show();

if it is difficult to understand follow that link: https://developers.google.com/web/fundamentals/codelabs/push-notifications/