This document represents the consensus of the group on the scope and features of the Vibration API. It should be noted that the group is aware of more advanced use cases that cannot be realised using this simpler first version. The intent is to address them in a future revision.
The Vibration API defines a means for web developers to programmatically provide tactile feedback in the form of vibration. The API is designed to tackle high-value use cases related to gaming, and is not meant to be used as a generic notification mechanism.
This specification defines conformance criteria that apply to a single product: the user agent that implements the interfaces that it contains.
Implementations that use ECMAScript to implement the APIs defined in this specification must implement them in a manner consistent with the ECMAScript Bindings defined in the Web IDL specification [[!WEBIDL]], as this specification uses that specification and terminology.
The vibrate() method, when invoked, MUST run the algorithm
for processing vibration patterns.
The rules for processing vibration patterns are as given in the following algorithm:
hidden attribute [[!PAGE-VISIBILITY]] is set to true,
abort these steps.
NotSupportedError exception [[!DOM4]] and abort these
steps.
NotSupportedError exception [[!DOM4]] and
abort these steps.
When the
visibilitychange event [[!PAGE-VISIBILITY]] is dispatched at
the Document, the user
agent MUST run the following steps:
hidden attribute [[!PAGE-VISIBILITY]] is set to true,
the user agent MUST suppress
the vibration produced by running the pre-existing instance of the
processing vibration patterns algorithm, if any.
hidden attribute [[!PAGE-VISIBILITY]] is set to false,
the user agent MUST restore
the vibration produced by running the pre-existing instance of the processing vibration
patterns algorithm, if any.
If the device does not provide a vibration mechanism, or it is
disabled, the user agent MUST
silently ignore any invocations of the vibrate() method.
In the following example the device vibrates for 1 second:
// vibrate for 1 second
navigator.vibrate(1000);
// or alternatively
navigator.vibrate([1000]);
In the following example the device vibrates for 1 second, is still for 0.5 seconds, and vibrates again for 2 seconds:
navigator.vibrate([1000, 500, 2000]);
The following example cancels any existing vibrations:
navigator.vibrate(0);
// or alternatively
navigator.vibrate([]);
The group is deeply indebted to Mounir Lamouri, Jonas Sicking, and the Mozilla WebAPI team in general for providing the WebVibrator prototype as an initial input.