LEARNING OBJECTIVES ⌵
- Silence native system audio chimes using the
silent: trueoption. - Define custom haptic vibration patterns using the
vibratemillisecond array ([vibrate, pause, vibrate, ...]). - Compare hardware vibration capabilities and limitations across Android, iOS, Windows, and macOS.
- Understand how host operating system Focus Assist, Do Not Disturb (DND), and device mute switches override web notification sensory outputs.
📖 The Mental Model & Story (Intuitive Foundation)
Imagine sitting in a quiet university library or a packed boardroom presentation. If your phone suddenly blasts a loud trumpet fanfare when a new marketing email arrives, you will be deeply embarrassed. However, if your phone gives you a subtle, rhythmic "double-tap" vibration in your pocket—or if your laptop silently displays a notification banner in the corner without making a peep—you stay informed without disturbing anyone.
+─────────────────────────────────────────────────────────────────────────────+
| SENSORY FEEDBACK SPECTRUM |
+─────────────────────────────────────────────────────────────────────────────+
| |
| [ 1. Silent Toast ] [ 2. Tactile Haptic ] [ 3. Full Alert ] |
| { silent: true } { vibrate: [100, 50, 100] } { renotify: true}|
| │ │ │ |
| ▼ ▼ ▼ |
| Visual Banner Only Subtle Pocket Rhythm Chime + Haptic |
| (Night mode, background sync) (Urgent chats, reminders) (Alarms, 2FA) |
| |
+─────────────────────────────────────────────────────────────────────────────+
The Web Notifications API provides two primary sensory levers:
- The
silenttoggle: Suppresses any audio chime or hardware buzz, presenting a purely visual notification. - The
vibratepattern array: Encodes custom haptic rhythms (like Morse code) directly into the device's physical vibration motor on supported mobile devices.
Technical Deep Dive & Specifications
The silent Boolean Option
The silent property instructs the host operating system to suppress all default notification sounds and vibrations:
const silentNotification = new Notification('Sync Complete', {
body: '142 files synchronized in the background.',
icon: 'https://example.com/icon.png',
silent: true // No OS chime, no vibration!
});
Precedence Rule: If you provide both
silent: trueand avibratepattern in the same options dictionary, the W3C specification dictates thatsilent: truetakes absolute precedence. The notification will remain completely quiet and motionless.
The vibrate Pattern Specification
The vibrate property accepts a sequence of unsigned integers representing millisecond durations. The array alternates between active vibration time and silent pause time:
vibrate: [ Buzz1, Pause1, Buzz2, Pause2, Buzz3 ]
// Example: SOS Morse Code in Haptics (... --- ...)
// Short: 100ms, Long: 300ms, Inter-element pause: 50ms, Letter pause: 200ms
const sosPattern = [
// S (...)
100, 50, 100, 50, 100,
200, // Pause between S and O
// O (---)
300, 50, 300, 50, 300,
200, // Pause between O and S
// S (...)
100, 50, 100, 50, 100
];
const urgentAlert = new Notification('🚨 Server Outage Detected', {
body: 'Production database latency exceeded 5000ms.',
vibrate: sosPattern,
icon: 'https://example.com/alert.png'
});
Popular Haptic Vibration Presets
| Preset Name | Vibration Array (ms) |
Tactical Feel / Sensation | Best Use Case |
|---|---|---|---|
| Subtle Tap | [50] |
Single crisp, light micro-haptic | Routine informational updates |
| Double Pulse | [100, 100, 100] |
Two quick distinct vibrations | Incoming direct messages |
| Heartbeat | [150, 150, 150, 600, 150, 150, 150] |
Thump-thump rhythm | Urgent alarms, critical alerts |
| Incoming Call | [500, 250, 500, 250, 500] |
Long ringing pulses | VoIP incoming calls, video rings |
Hardware & OS Compatibility Matrix
+─────────────────────────────────────────────────────────────────────────+
| SENSORY FEATURE SUPPORT BY PLATFORM |
+─────────────────────────────────────────────────────────────────────────+
| Platform | `silent: true` | `vibrate` Array Pattern |
|────────────────────────────┼────────────────┼───────────────────────────|
| Android (Chrome / Edge) | ✅ Supported | ✅ Full Hardware Support |
| Windows 10 / 11 | ✅ Supported | ❌ Ignored (No Motor) |
| macOS (Chrome / Safari) | ✅ Supported | ❌ Ignored (No Web API) |
| iOS Safari (16.4+ PWA) | ⚠️ OS Governed| ❌ Unsupported |
| Linux Desktop | ✅ Supported | ❌ Ignored |
+─────────────────────────────────────────────────────────────────────────+
What Happened to the sound Property?
In the original 2012 drafts of the W3C Notifications API, there was a sound: 'alert.mp3' property. This property was deprecated and completely removed from all modern web browsers for the following reasons:
- Autoplay Abuse: Malicious websites abused custom sound URLs to blast loud audio advertisements.
- OS Sound Uniformity: Host operating systems (Windows Action Center, macOS, Android) enforce user-configured notification chimes so users can distinguish notification origins by their system themes.
- Alternative Solution: If your application is active in the foreground and requires a custom chime, use the Web Audio API or
new Audio('chime.mp3').play()inside your active page, paired withsilent: trueon the notification.
💻 Interactive Code Playground
Starter Code
Save this file as index.html and open it on your computer or Android mobile device:
Line-by-Line Code Breakdown
- Lines 131–136: Defines structured haptic presets with exact millisecond vibration/pause ratios.
- Lines 147–156: Dynamically computes visual widths for each vibration burst and pause gap using CSS flex weighting.
- Lines 176–183: Builds the
NotificationOptionsdictionary. Whensilent: trueis chosen, thevibrateproperty is omitted, adhering to spec precedence rules. - Line 185: Dispatches the configured multi-sensory notification instance.
Expected Browser Render Output
+────────────────────────────────────────────────────────────+
| 📳 Haptic & Sensory Notification Studio |
| Select a sensory profile below to test silent notifications|
| |
| [ 🔇 Silent Mode ] [ ⚡ Subtle Tap ] |
| silent: true [60] |
| |
| [ 💬 Double Pulse ] [ 🚨 Emergency SOS ] |
| [120, 80, 120] [100,50,100,50,100...] |
| |
| +────────────────────────────────────────────────────────+ |
| | Selected Profile: Double Pulse ([120, 80, 120]) | |
| | [█████████░░░░░░█████████] | |
| +────────────────────────────────────────────────────────+ |
| |
| [ Dispatch Configured Notification (Blue CTA) ] |
| Status: Ready. Click a profile and dispatch. |
+────────────────────────────────────────────────────────────+🏋️ Hands-On Exercise
🎯 The Challenge: Critical Server Alert Dispatcher
Instructions:
- Create a function
dispatchServerMonitoringAlert(alertLevel, serverName, metricName, metricValue)wherealertLevelcan be'info','warning', or'critical'. - Configure sensory options based on
alertLevel:'info': Title"ℹ️ Server Info: " + serverName,silent: true,body: metricName + ": " + metricValue.'warning': Title"⚠️ Server Warning: " + serverName,silent: false,vibrate: [150, 100, 150].'critical': Title"🔥 CRITICAL ALERT: " + serverName,silent: false,vibrate: [300, 100, 300, 100, 500],requireInteraction: true.
- Dispatch the notification and return the instance.
🏁 Starter Code Sandbox
⚠️ Common Pitfalls
- Passing Audio URLs to
sound: Thesoundoption is deprecated and non-functional in all modern browsers. Do not attemptsound: '/audio/alert.mp3'. - Combining
silent: truewithvibrate: If both are set,silent: trueoverridesvibrate, muting the haptic motor entirely. - Assuming Desktop Vibration: Laptops and desktop monitors do not have vibration motors. Vibration arrays only execute on mobile/tablet devices with haptic actuators.
💡 Pro Tips
- Foreground Custom Chimes via Web Audio API: When
document.visibilityState === 'visible', dispatch asilent: truedesktop notification and play a rich spatial audio chime inside the page using the Web Audio API (AudioContext). - Respecting System DND & Focus Assist: Never attempt to "work around" operating system Focus Modes. If Windows Focus Assist or macOS Do Not Disturb is active, the OS intentionally suppresses alerts for user productivity.
📌 Key Takeaways
silent: truesuppresses all audio chimes and vibrations for unobtrusive visual notifications.vibrateaccepts an array of alternating vibration and pause durations in milliseconds ([vibe, pause, vibe, ...]).- If both
silent: trueandvibrateare supplied,silent: truetakes precedence. - Hardware vibration is supported on Android devices, while desktop platforms safely ignore the
vibratearray. - The legacy
soundproperty is deprecated and removed; custom foreground audio should be handled via the Web Audio API. - --