Modern mobile devices can vibrate. The Vibration API allows Web apps the trigger vibration of the device (if its supported by the hardware).
Support by browsers and operating systems might be limited.
Vibrate the device for 100 ms:
const didVibrate = window.navigator.vibrate(100);
or
const didVibrate = window.navigator.vibrate([100]);
Check if browser supports vibrations
if ('vibrate' in window.navigator) {
// browser has support for vibrations
} else {
// no support
}
An array of values describes periods of time in which the device is vibrating and not vibrating.
window.navigator.vibrate([200, 100, 200]);