Open Bug 971729 Opened 12 years ago Updated 3 years ago

[System] navigator.vibrate() is available even when the device has no vibrator

Categories

(Core :: DOM: Device Interfaces, defect, P3)

x86
macOS
defect

Tracking

()

People

(Reporter: mcav, Unassigned)

References

Details

The IDL docs for navigator.vibrate()[1] state that "If the device does not have a vibrator, this function does nothing." Presently, this works as described. However, because the function is always present, even if the hardware does not have a vibration motor, there is no way to detect whether or not the device supports vibration. Even Firefox Nightly (just the plain-old browser) does a no-op instead of nulling the function. Use-cases: - Clock wants to hide the "Vibrate" option for alarms if the hardware does not support vibration. (bug 964770) - Apps may want to offer alternate functionality (e.g. visual feedback for input or games) if the system does not support vibration. I asked if this was expected on b2g-dev; Jonas Sicking's response was "We should probably make the function not exist if the hardware doesn't support vibration." Some places in Gaia check for the presence of `navigator.vibrate` first (as they should); some do not. So this would require updating any unqualified references in Gaia, unless we find some other way to indicate whether or not the device actually supports vibration. [1]: https://mxr.mozilla.org/mozilla-central/source/dom/interfaces/base/nsIDOMNavigator.idl?rev=b405f493e834#80
Blocks: 964770
Component: Gaia::System → DOM
Product: Firefox OS → Core
This is pretty easy to hook up if we have a way to test whether the hardware supports vibration.
I thought most APIs we have are set to have a property/object that exists but evaluates to false in an |if| statement, i.e. I'd expect something like |if (navigator.vibrate) { }| to work for feature detection - but not sure if that works when it's supposed to be a function.
(In reply to Robert Kaiser (:kairo@mozilla.com) from comment #2) > I thought most APIs we have are set to have a property/object that exists > but evaluates to false in an |if| statement, i.e. I'd expect something like > |if (navigator.vibrate) { }| to work for feature detection - but not sure if > that works when it's supposed to be a function. That check will work fine if there is no name "vibrate" in navigator.
(In reply to Boris Zbarsky [:bz] from comment #1) > This is pretty easy to hook up if we have a way to test whether the hardware > supports vibration. Marcus, do you know if we have an existing way to determine this?
Flags: needinfo?(m)
Not that I know of, but I'm completely unfamiliar with how the hardware vibrate. Someone lower-level in the stack might know, but based on what I see[1] it seems like that doesn't presently exist. [1]: https://github.com/dhuseby/gecko/blob/master/hal/Hal.h
Flags: needinfo?(m)
Component: DOM → DOM: Device Interfaces
Priority: -- → P3
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.