puter.notifications.disable() Turns push notifications off for your app.
Notifications still reach your app live while it's open.
On a website, it ends this browser's push subscription for your app and removes it from Puter. Only the subscription Puter made is removed, so a subscription another push service made on your site stays as it is. The browser's permission isn't changed, so a later enable() turns pushes back on without a prompt.
The choice sticks. Page loads don't turn pushes back on, because onPush() only keeps a subscription current after enable(). Call enable() from a click to turn them on again.
Inside the Puter desktop, it removes the permission that requestPermission() asks for, the same as the user turning your app off in Puter's settings. Your notifications stop going out as pushes to every device of the user, not only this browser. A later enable() shows Puter's permission dialog again.
puter.notifications.disable()
puter.notifications.disable(options)
options (Object) (optional)
| Option | Type | Description |
|---|---|---|
serviceWorker |
String |
The path of the worker passed to enable(). When it's set, only that worker's subscription is removed. Without it, Puter's subscription is removed under whichever of your site's service workers holds it. Only used on a website. |
A Promise that resolves to true when a subscription was removed, and false when there was none. Inside the Puter desktop, it resolves true when your app held the permission. It resolves false in a browser that can't receive pushes.
If Puter can't remove the subscription, the promise rejects with an error carrying message and code, such as push_unavailable when this server has no push notification service. This browser's subscription is ended either way. Inside the Puter desktop, it rejects with ipc_handler_failed when the permission couldn't be removed.
document.getElementById('pushes-off').addEventListener('click', async () => {
await puter.notifications.disable();
puter.print('Push notifications are off<br>');
});