-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Require user activation for navigator.vibrate #29
Comments
@johannhof are you aware of other Web APIs that have spec'd this restriction (i.e. not considered an implementation detail)? If so, please drop a pointer so we make sure the prose remains consistent. |
User activation has had a long history in spec land AFAIR, and it is currently specified in https://html.spec.whatwg.org/multipage/interaction.html#tracking-user-activation We are probably interested in the transient activation boolean flag, which several specs seem to check for at this point. https://w3c.github.io/pointerlock/#dom-element-requestpointerlock says "Pointer lock is a transient activation-gated API, therefore a requestPointerLock() call MUST fail if the relevant global object of this does not have transient activation. This prevents locking upon initial navigation or re-acquiring lock without user's attention.". The language used in algorithms in other specs (e.g. https://w3c.github.io/remote-playback/#prompt-user-for-changing-remote-playback-state or https://wicg.github.io/eyedropper-api/#dom-eyedropper-open) looks like this: "If the relevant global object of this does not have transient activation, return a new promise rejected with a "NotAllowedError" DOMException." |
Thanks @rakuco! That's plenty of good precedent. Also whatwg/html#5129 @johannhof does transient activation boolean flag gating for |
Alternatively consider sticky activation, which seems closer to what Chrome's doing. Vibration might be useful for notifying the user of something that happens a while later than the initial interaction? |
Sorry for the delay, I was on vacation. Thank you for chiming in to help! Chrome seems to use the sticky activation API indeed. Independent of whether that is ideal or not it's probably reasonable to update the spec to match current implementation(s). You can find some example usage in other specs here. |
Thanks @johannhof for confirming Chrome's implementation choice. Per APIs gated by user activation and as suggested by folks on this issue, we have two alternatives: transient activation and sticky activation. Given the major implementation has chosen sticky activation, it is reasonable to recommend that in the spec unless good reasons surface not to. Proposed spec change: Inject the following step as the first one in https://w3c.github.io/vibration/#dfn-perform-vibration:
Note that there's already a step in this place that allows implementations to bail out for whatever reason which makes also existing sticky activation gated implementations compliant:
(I'm not a fan of such a catchall "may" but that is the escape hatch we put there long time ago after some debate IIRC.) @johannhof looks good? I'll put up a PR if good. FTR: Web APIs that reference either transient activation or sticky activation.
|
Also: - Add dfns: this, relevant global object, sticky activation - Remove unused refs: spin the event loop, Navigator - Link to the "user agent" dfn (Future work: refactor to use the fancier ref syntax.) Fix #29
Proposed spec patch: #30 |
This was previously discussed in WICG/interventions#47. It looks like Chrome shipped this restriction, see https://chromestatus.com/feature/5644273861001216. I think it makes sense to make this change in the spec as well.
The text was updated successfully, but these errors were encountered: