Skip to content

isSupported doesn't cover iOS haptics. Missing capability detection API #23

@jayk293

Description

@jayk293

isSupported checks for navigator.vibrate (Vibration API), which iOS Safari doesn't implement, so it returns false on iOS. But .trigger() still fires haptics on iOS via the <input type="checkbox" switch> fallback you've built in.

Discovered this when I wanted to provide a toggle for enabling haptics in my app, expecting this toggle to not be shown in the desktop version.
if (WebHaptics.isSupported) showHapticsToggle(); // This hides on iOS Safari, even though haptics work

To me, isSupported is more of a check on whether the Vibration API is supported, rather than haptics are supported on the device.

Would you be open to amending isSupported or adding like a canHaptic property that covers both paths?

static readonly canHaptic =
    typeof navigator !== "undefined" &&
    (typeof navigator.vibrate === "function" || navigator.maxTouchPoints > 0); 

navigator.maxTouchPoints > 0 is true on iOS and Android, false on desktop, matching the environments where haptics actually fire.

Happy to open a PR if this direction makes sense to you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions