-
Notifications
You must be signed in to change notification settings - Fork 28
Description
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