puter.notifications.requestPermission()Asks the user to let your app send push notifications. Your notifications always show in the user's Puter notifications panel; this decides whether they also reach the user's devices when they have neither Puter nor your app open.
It asks for the notifications:push permission. Inside the Puter desktop the prompt is a dialog; on a website it opens in a popup on the Puter origin, so call it from a user gesture such as a click. If the user already allowed it, it resolves true without asking.
When the user allows it, Puter also turns push notifications on in the browser they answered in, unless they are on there already or the browser blocks them. To offer that in a browser where your app already holds the permission, call enablePush().
The user can change their mind later. Your notifications still show in Puter either way.
puter.notifications.requestPermission()
None.
A Promise that resolves to true if your app may send pushes, and false if the user declined.
Ask from a button
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<button id="allow">Notify me on my phone</button>
<script>
document.getElementById('allow').addEventListener('click', async () => {
const allowed = await puter.notifications.requestPermission();
puter.print(allowed ? 'Pushes on<br>' : 'Pushes off<br>');
});
</script>
</body>
</html>