Skip to content

User gesturesΒ #142

@AshleyScirra

Description

@AshleyScirra

Description

User gestures (aka user activation) restrict certain sensitive actions, such as opening a popup window, to only be allowed in response to a user gesture, i.e. some kind of user input event. Browsers currently significantly differ in their implementation of this though, and it causes awkward compatibility problems.

Rationale

The model implemented by Chrome works well: there are essentially two flags and a short timeout. Other browsers do not support this though, only considering synchronous code run inside a user input event as a user gesture.

This causes problems such as:

  • difficulty running async code for input events (an await can mean you lose the gesture)
  • difficulty delegating work to Web Workers (postMessage can mean you lose the gesture)
  • blocking use of new APIs like OffscreenCanvas (in a web worker, you never have a user gesture)
  • causing other browsers to implement case-by-case exceptions e.g. allowing user gestures to propagate with certain APIs, but not others; or modifying the design of APIs (e.g. Clipboard API) to solve a similar problem

Chrome's model solves all these problems, assuming there is not too long a wait. However in many cases that is perfectly sufficient. For example converting a Blob to an ArrayBuffer is async but will likely complete very quickly for small blobs; in Chrome a user gesture can still be used afterwards, but in other browsers it cannot.

Specification

"Tracking user activation" in the HTML spec: https://html.spec.whatwg.org/multipage/interaction.html#tracking-user-activation

Tests

https://wpt.fyi/results/html/user-activation

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions