Skip to main content

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โ€‹

APIChromeEdgeFirefoxSafariiOS SafariBaseline
Navigator.vibrateโœ… 32+โœ… 79+โŒ removed in 129 [1,2,3]โŒโŒLimited
  1. 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).
  2. 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).
  3. 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 check
  • vibrate(pattern) โ€” vibrates for a duration or pattern (ms), returns whether it was triggered
  • stopVibration() โ€” stops any ongoing vibration
  • vibratePulse(duration?) โ€” a short pulse (default 200ms)
  • vibrateNotification() โ€” a preset notification pattern

See the API reference for full signatures.