new Notification(...) is deprecated

Earlier I showed this example of the Notification API:

Notification.requestPermission(perm => new Notification('HEY!!'));

Unfortunately this uses a deprecated feature. The window.Notification constructor is not marked as deprecated! However, it’s marked as deprecated in Chrome on Android. The Brave New World is service-worker notifications, which are triggered like this:

Notification.requestPermission(perm =>
  navigator.serviceWorker.ready.then(reg => reg.showNotification("HEY!!")));

In other words, ServiceWorkerRegistration.showNotification is the replacement for new Notification. For this to work, you need to install a service worker. I’ve updated the service worker at /service-worker.js so that I/you can run:

Notification.requestPermission((perm) => {
  if (perm == "granted") {
    window.navigator.serviceWorker.ready.then(reg =>{
        method: "notify",
        title: "HEY!!",
        options: {body: "This is some extra text under the title."}
I just released Vidrio, a free app for macOS and Windows to make your screen-sharing awesomely holographic. Vidrio shows your webcam video on your screen, just like a mirror. Then you just share or record your screen with Zoom, QuickTime, or any other app. Vidrio makes your presentations effortlessly engaging, showing your gestures, gazes, and expressions. #1 on Product Hunt. Available for macOS and Windows.

With Vidrio

With generic competitor

More by Jim

Tagged . All content copyright James Fisher 2017. This post is not associated with my employer. Found an error? Edit this page.