puter.notifications.on('click')Calls handler when the user clicks one of your app's notifications, so you can open the screen it's about.
Clicks reach your app in two ways:
click handlers. A page without a click handler goes to the notification's url instead, which is the url your onPush() handler returned, or else the notification's target. When no page is open, the tap opens that url, and the new page's first click handler gets the click.A click that arrives before your first click handler is added, such as the one that opened your app, goes to that first handler, once. Handlers added after it don't get it, so add your handler early during startup.
To remove a handler, call puter.notifications.off('click', handler).
puter.notifications.on('click', handler)
puter.notifications.off('click', handler)
handler (Function) (required)
Called with:
uid (String): The notification's id.target (String | null): The target the notification was sent with. On a website, it's null for a tap on a sensitive notification.data (any): The data it was sent with, or null. On a website, it's also null for a tap on a sensitive notification.It returns puter.notifications, so calls can be chained.
Route a click to the right screen
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
puter.notifications.on('click', ({ target, data }) => {
if ( target?.startsWith('/chats/') ) {
puter.print(`Opening chat ${data?.chatId}<br>`);
}
});
</script>
</body>
</html>