Friday, 14 July 2023

Push Notifications Request for edge

For a client project, I recently implemented a feature that enables push notifiactions for users. For this I use push.js. During development I noticed that the Notifications Allow prompt appears automatically on Chrome, on Firefox a workaround was needed (a click listener was registered on the page which makes the notification prompt appear on the first click). Only for Edge I could not find a way, because Edge blocks all notifications by default. Now I came across the following page https://www.pushengage.com/. If you scroll down to "See a Live Push Notification Example" and click on one of the buttons, a accept notification prompt also appears in Edge. Can anyone help me how to achieve this in my application as well? Apparently it is possible somehow.

Here is a minifed version of my application (the push notifications part).

import Push from 'push.js';

init() {
     document.addEventListener('click', () => {  // cause of some browser specific behaviour add click listener to trigger the permissions request (e.g. for firefox)
        if (Push.Permission.get() === 'default' && this.isInitial) {
          Push.Permission.request();
        }
      });

const onGranted = (function onGranted() {
      Push.create("My Notification", {
      body: 'Some text',
      icon: someIcon,
      link: someUrl,
      vibrate: [200, 100],
       });
      }
    }).bind(this);
    Push.Permission.request(onGranted, onDenied);
}


from Push Notifications Request for edge

No comments:

Post a Comment