vibrate
Trigger and stop device vibration via the Vibration API.
Import: @rtorcato/browser-common/vibrate
๐ MDN: Vibration API ยท ๐ caniuse: vibration
Not supported on Safari (desktop or iOS).
Browser supportโ
| API | Chrome | Edge | Firefox | Safari | iOS Safari | Baseline |
|---|---|---|---|---|---|---|
Navigator.vibrate | โ 32+ | โ 79+ | โ removed in 129 [1,2,3] | โ | โ | Limited |
- Firefox: Until Firefox 26 included, when the vibration pattern was too long or any of its elements too large, Firefox threw an exception instead of returning false (bug 884935).
- Firefox: From Firefox 32 onwards, when the vibration pattern is too long or any of its elements too large, it returns true but truncates the pattern (bug 1014581).
- Firefox: Beginning in Firefox 72, this is not supported in cross-origin iframes.
โ
supported ยท โ partial ยท โ not supported ยท [n] see note. Generated from MDN browser-compat-data and web-features. caniuse: Navigator.vibrate
Exampleโ
import {
isVibrationApiAvailable,
vibrate,
stopVibration,
vibratePulse,
vibrateNotification,
} from '@rtorcato/browser-common/vibrate'
if (isVibrationApiAvailable()) {
vibrate([200, 100, 200])
vibratePulse(300)
vibrateNotification()
stopVibration()
}
Exportsโ
isVibrationApiAvailable()โ feature checkvibrate(pattern)โ vibrates for a duration or pattern (ms), returns whether it was triggeredstopVibration()โ stops any ongoing vibrationvibratePulse(duration?)โ a short pulse (default 200ms)vibrateNotification()โ a preset notification pattern
See the API reference for full signatures.