Skip to content

Notifications

The notifications namespace manages the current signed-in browser's native Web Push subscription. It is available only when the manifest declares notifications.webPush: true and pins SDK 2.1.0 or later.

notifications.status()

Inspects browser support, permission, and subscription state without prompting:

ts
notifications.status(): Promise<{
  state:
    | "unsupported"
    | "prompt"
    | "denied"
    | "unsubscribed"
    | "subscribed";
  permission: NotificationPermission | "unsupported";
  subscribed: boolean;
}>

Use this during rendering to decide whether to show an enable, disable, or browser-settings instruction.

notifications.subscribe()

Requests permission, installs the platform's narrowly scoped worker, and registers this browser for the current user:

js
button.addEventListener("click", async () => {
  const status = await opencloud.notifications.subscribe();
  renderNotificationState(status);
});

Call it directly from a click or tap. It throws USER_GESTURE_REQUIRED when the browser exposes user-activation state and no active gesture exists. It returns denied rather than repeatedly prompting after the user denies permission.

notifications.unsubscribe()

Removes the platform registration and unsubscribes the current browser:

js
await opencloud.notifications.unsubscribe();

The operation is safe when no browser subscription exists. It does not change the browser's permission setting.

Subscriptions belong to the browser session that created them and never expose their endpoint or encryption keys to application code. See Web Push notifications for the manifest and Function send API.

Self-hosted infrastructure for agent-built applications.