Repository navigation
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
awaitcan mean you lose the gesture) - difficulty delegating work to Web Workers (
postMessagecan 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
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsProposed
Activity
foolip commentedon Sep 22, 2022
Thanks for proposing this, @AshleyScirra!
Can you say more about this? Are there any
OffscreenCanvasAPIs that require a user gesture?cc @mustaqahmed who's done a lot of work on user gestures in Chrome.
AshleyScirra commentedon Sep 22, 2022
We have a game engine that supports running entirely in a web worker with OffscreenCanvas. In our architecture input events are forwarded to the worker via postMessage(), it runs the entire engine and all logic in the worker, and then it posts back for calls to any APIs not available in a worker (window.open, WebRTC, etc...)
However this means calls are never synchronously in a user input event, and so in some browsers we lose the ability to use any user-gesture limited APIs at all. So we have to turn off using a web worker and stop using OffscreenCanvas, just so we can keep within the user gesture rules. I know OffscreenCanvas isn't supported outside of Chromium yet, but even when it is, this is a blocking issue for us to switch to using it.
foolip commentedon Sep 22, 2022
I see, so an example might be when there's a "fullscreen" button in the game's UI, and you need to actually run the game engine to know that it was clicked, and then do the
element.requestFullscreen()call on the main thread. Is that the kind of thing that's made complicated by the model in some browsers?mustaqahmed commentedon Sep 22, 2022
To the best of my knowledge, most other browsers use the old HTML model that required calling activation-gated APIs synchronously in appropriate event handlers, or asynchronously after a (undefined) propagation. That undefined part was known to have fundamental problems, and every browser (including pre-M72 Chrome) added unpredictable workarounds to make it work. The primary motivation for the current HTML model was to support async usage of user activation in a well-defined manner that is agnostic to any propagation scheme in JS.
AshleyScirra commentedon Sep 22, 2022
Yes, exactly. It might seem a roundabout approach to making the call, but if you make middleware/game engines/libraries that run in a worker, you can end up with that situation; by the time you try to call
requestFullscreen()you've lost the user gesture. I suppose a similar problem may arise with trying to host WebAssembly builds of codebases in a worker. The only good workaround is to stop using a worker and run everything on the main thread again.I guess this is a variant of "difficulty delegating work to Web Workers", but I called it out separately as giving up on running code off main thread is a pretty significant consequence.
[-][Interop 2023 proposal] User gestures[/-][+]User gestures[/+]tbondwilkinson commentedon Oct 24, 2022
User gestures is a P2 for Google's closure library
"Allows more work to be done asynchronously, which unblocks migration to Promise."
marcoscaceres commentedon Oct 26, 2022
WebKit implements the "new" model in HTML, and has for a long time.
About the problem @AshleyScirra outlines, understood. I guess it would be good to see some examples. WebKit, for instance, allows quite a bit of time before consuming the activation (this obviously shouldn't be relied on and can change without notice!).
So, I guess I'm wondering why one would do:
Instead of:
marcoscaceres commentedon Oct 26, 2022
Just so we have some more context, the APIs in WebKit that either consume user activation or check for transient activation are:
So the discussion needs to be framed around when the above are a problem (the list is not exhaustive, other engines may support more).
AshleyScirra commentedon Oct 26, 2022
@marcoscaceres - it doesn't look to me like Safari does support this. This WebKit bug is still open and some of the cases, such as reading a blob, still prevent a user gesture from working based on a quick test now in Safari 16.1.
As for the requestFullscreen workaround, middleware like Construct's game engine, and probably also anything compiled to WebAssembly and running in a worker, doesn't know what the intent is with any given input event. It uses an architecture where it simply forwards all input events to the worker, runs logic, and then posts messages back to the DOM to run any APIs not available in a worker. We can't request fullscreen and then cancel it on every single input event just in case it does want to enter fullscreen - it would be unusable with constant flickering for the user.
21 remaining items
mustaqahmed commentedon Nov 9, 2022
Based on the comments above, I am splitting "Bucket 1" (from in my previous comment) into two sub-buckets as follows, and proposing to target Bucket 1.1 for 2023:
Bucket 1: specs that properly reference the HTML activation concept and are on a standards track
Bucket 1.1: already supported by major browsers
Bucket 1.2: not yet supported by major browsers
(I moved Fullscreen to Bucket 1.2 because Safari doesn't support consumption yet.)
EdgarChen commentedon Nov 9, 2022
Sounds good, thanks for your responses. :)
marcoscaceres commentedon Nov 10, 2022
The above seems reasonable... with the hope that at least Fullscreen will also get included (it's hopefully small change, so I'd encourage us to add it).
With Payment Request, at least Chrome and Safari should be fully interoperable and already doing the right thing per spec.
And even though Web Share is not available across all platforms, it should be broadly interoperable with respect to user activation (for where it is available).
mustaqahmed commentedon Nov 11, 2022
To complete @marcoscaceres's list above, here is Blink's Web Share code.
At this point, we can broaden our 2023 Interop goal above (i.e. Bucket 1.1) to:
A. add all three of Fullscreen, Payment and Web Share, assuming new implementations are easy, or
B. add just Web Share so that cross-browser implementation of the other two API doesn't become a blocker.
Please vote for🅰️ or 🅱️ so that we can quickly decide.
marcoscaceres commentedon Nov 14, 2022
jgraham commentedon Nov 15, 2022
We were working on the basis of the "Bucket 1.1" scope, and don't think the other work is the same level of priority.
Also, as a process point, this is extremely late to be changing the scope, given that people are already firming up positions, and trying to broaden the scope at this stage will invalidate that work, and thus is unlikely to be well received.
marcoscaceres commentedon Nov 15, 2022
@jgraham, Happy to push this to 2024, as the API listed are broadly interoperable anyway.
I guess in parallel, we can all come up with a broader plan interop plan by expanding on @mustaqahmed's list (#142 (comment)).
I'd really like to cross reference that with the larger list of APIs that depend on some kind of user gesture.
nairnandu commentedon Feb 1, 2023
Thank you for proposing user gestures for inclusion in Interop 2023.
We wanted to let you know that this proposal was not selected to be part of Interop this year. We had many strong proposals, and could not accept them all. As discussed in the issue comments, it was hard to find a subset of this proposal that was itself an interop priority and only depends on features that are themselves widely implemented.
For an overview of our process, see the proposal selection summary. Thank you again for contributing to Interop 2023!
Posted on behalf of the Interop team.
marcoscaceres commentedon Feb 6, 2023
We should definitely see if we can get this into 2024. Hopefully we can just reopen the issue when the time is right?
marcoscaceres commentedon Feb 6, 2023
(In other news, the User Activation API is enabled in Safari Tech Preview… so, that’s something 😊)
foolip commentedon Feb 6, 2023
That would be great. We haven't defined the process for next time yet, but I expect a new issue will be clearer. It would need to explain what's changed since last time.
AshleyScirra commentedon Sep 15, 2023
Can I request that this proposal is resubmitted for Interop 2024? I could file a new issue but it seems valuable to preserve the existing discussion. (I don't appear to have permission to reopen this issue myself.)
foolip commentedon Sep 15, 2023
@AshleyScirra please file a new issue and link to this one. I'd suggest naming it user activation to match spec terminology.
AshleyScirra commentedon Sep 15, 2023
Re-submitted for 2024 at #428.