MDN self-hosted library · e01.org

Notifications API

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

js
btn.addEventListener("click", () => {
  let promise = Notification.requestPermission();
  // wait for permission
});
js
if (Notification.permission === "granted") {
  const notification = new Notification("New message from Alice", {
    body: "Hey, are you free for lunch?",
    navigate: "/messages/alice",
  });
}