The One-Liner That Sends Browser Notifications (No App Needed)

The One-Liner That Sends Browser Notifications (No App Needed)

Hey everyone,

Ever wanted to show a notification to your user even when your website isn’t open? Like a reminder, a message, or an alert? That’s exactly what the Notifications API is built for.

It’s native, requires no app, and works right from the browser.

The Code: new Notification()

First ask for permission, then fire the notification. That’s the whole flow.

javascript
const button = document.querySelector("#notify-btn");

button.addEventListener("click", async () => {
  // Step 1: Ask for permission
  const permission = await Notification.requestPermission();

  // Step 2: If they said yes, send it
  if (permission === "granted") {
    new Notification("Hey! 👋", {
      body: "Your report is ready to download.",
      icon: "/logo.png",
    });
  }
});

Why this is a win:

  • No app needed: Users get real OS-level notifications, the same ones they get from native apps.
  • Dead simple: Two steps. Ask permission, send notification. That’s it.
  • Customizable: Add an icon, a body message, and even a click handler to bring the user back to your tab.

One thing to keep in mind:

You can only ask for permission once. If the user clicks “Block”, the browser remembers and you can never ask again. So time it well, trigger the prompt after the user has already gotten value from your app, not the second they land on the page.

Happy coding!
Marko