iOS Safari doesn’t expose a Haptic Feedback JavaScript API. ios-haptics uses a clever DOM-based workaround to fire the Taptic Engine from the browser.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/tijnjh/ios-haptics/llms.txt
Use this file to discover all available pages before exploring further.
The checkbox switch trick
Safari 17.4 (iOS 17.4, March 2024) introduced<input type="checkbox" switch> — a toggle control that renders as a native switch and fires haptic feedback when clicked. ios-haptics exploits this behavior: on every haptic() call, it creates the element, clicks it to trigger the haptic, then immediately removes it from the DOM.
The label element is hidden (
display: none) and marked aria-hidden="true", so it is invisible and completely inaccessible to assistive technologies.Android fallback
On Android,navigator.vibrate() is checked first. If available, it takes priority over the checkbox trick and is used for all haptic calls.
| Call | Vibration pattern |
|---|---|
haptic() | navigator.vibrate(50) |
haptic.confirm() | navigator.vibrate([50, 70, 50]) |
haptic.error() | navigator.vibrate([50, 70, 50, 70, 50]) |
confirm and error encodes alternating vibrate/pause durations in milliseconds, producing two and three distinct pulses respectively.
Device detection
supportsHaptics uses window.matchMedia("(pointer: coarse)") to detect touchscreen devices. This returns true on phones and tablets and false on desktop browsers.
window is undefined, so supportsHaptics safely returns false without throwing.
Error handling
Every haptic call is wrapped in atry/catch. If the DOM manipulation fails for any reason — for example in an environment where document.createElement behaves unexpectedly — the error is silently swallowed. Calls to haptic() will never throw.