Search code examples
javascripthtmlweb-notifications

Web Notification API - website doesn't need to be open?


I noticed some news sites such as Washington Post are able to pop up Web Notifications even though I don't have the site open in a tab. I don't recall this being possible before. How is it even possible for a website to execute the JS necessary if the site isn't open? How does one accomplish this using Web Notifications, is there a particular setting to accomplish this?


Solution

  • I believe they are using Push Notifications via Service Workers.

    You can check the current support status to see if it's fit for you. It's well supported in modern browsers (although perhaps not the full specification).

    A service worker is a script that your browser runs in the background, separate from a web page, opening the door to features that don't need a web page or user interaction. Today, they already include features like push notifications and background sync.

    and

    A service worker has a lifecycle that is completely separate from your web page.