Menu

Making a Timer Notify Reliably: Notifications API, Audio Autoplay Rules and Wake Lock
📰

Making a Timer Notify Reliably: Notifications API, Audio Autoplay Rules and Wake Lock

DEV Community: javascript·Nomad Wozo·about 8 hours ago
#x6AkQTF3
#devtojavascript#devto#dev#start#screen
Reading 0:00
15s threshold

A countdown that shows the right number is only half a timer. The other half is the moment it ends: a sound, a system notification, or at least a screen that's still on when you glance over. All three of those are gated by browser rules, and every one of those rules is easier to satisfy at the moment the user presses Start than at the moment the timer runs out.

This post covers what the docs and specs say about each API, and one pattern that ties them together.

Rule 1: Notification permission belongs inside a click

The Notifications API has three permission states: default (not asked yet), granted , and denied . MDN notes that when the result is default , the app should act as if permission was denied.

The WHATWG Notifications standard itself doesn't spell out a gesture requirement. The browsers do.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.