-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Add some mechanism to know that a message event was triggered by user activation #1983
Comments
I don't think we can use
|
But can you elaborate on your "leak" concern? Isn't it fine for any origin to know at any time whether it's currently inside the context of "triggered by user activation" algorithm? It can figure that out already (at least in blink) by trying to write to the clipboard. |
I don't see why we would make this MessageEvent-specific. After all it also flows through various other interesting things like setTimeouts and such. |
Yeah, that was my thinking too. Malte makes a good point that this is probably mainly useful cross-document (because within a single document there's no security boundary - just like But I can imagine some scenarios where it's useful to know even within a document. For example, you want to do a window.open either directly or (if you can tell it'll get blocked) via some additional "click here to open" UI. |
I have no preference in API really. If we can make it work for Exposing this will unlock a lot of use cases. For example it is rarely possible to use In AMP we'd like to allow iframes to request resize in response to a user gesture, which is very similar. |
If we expose it it should be exposed on the global I think since it's a task-annotation effectively. But I'm not sure we have described the underlying concept well enough to expose an API. E.g., integration with a theoretical interaction event specification is missing, |
Global sounds pretty reasonable to me. It also won't leak to other origins since it's not on the whitelist of cross-origin-accessible global properties. I guess it'd be only on Window, not on WorkerGlobalScopes. @annevk we have a separate bug to define this better; #1903. Do you think straightening that out is a prerequisite to speccing/shipping an API that reflects it? We also need multi-vendor interest, of course. I guess we should let this thread settle a bit further before we send up the signal flares in that direction though. |
Whether it needs to be exposed in workers depends on the semantics of what OP is requesting. Fairly easy to I think whether I'm comfortable with just adding an API without corresponding architecture depends largely on how interoperable implementations are today. Extending it to messaging as requested by OP would require some suitable definition though as there's a myriad of interpretations possible. |
I just want to pitch in and highlight the use case of using workers. With OffscreenCanvas it's now becoming feasible to run an entire game engine in a worker. However at the moment a game engine in a worker never has a user gesture. Considering some major features like starting audio playback are limited to user gestures, this issue amounts to blocking use of OffscreenCanvas for games. This is complicated by the fact various APIs are unavailable in a worker. So playing audio when the user taps the screen would probably end up working like this: "touchstart" event in main document -> postMessage() -> run game logic in worker -> postMessage() -> play audio in main document For the audio playback to be allowed, the user gesture needs to be propagated through two separate postMessages(). Alternatively if the main document could "save" the user gesture to use it later, that could work too. A related case is using user gestures with async code. For example if you want to prepare data to copy to the clipboard asynchronously, you can never copy it, because you lose the user gesture by the time the data is ready. I wrote more about this issue here: https://discourse.wicg.io/t/user-gesture-restrictions-and-async-code/1640 |
Thanks for the scenario! In chromium @mustaqahmed is experimenting with a simpler model for gestures that should solve most of what you've described. Still, probably worth thinking specifically about explicit ways of passing 'activation' to a worker - I filed this chromium bug. Is the ability to play audio in a Worker tracked anywhere? There's @hoch's AudioWorklet proposal, but I don't think the use case is the same there (in that case you really want your audio work isolated from the rest of the application, where you want it running on the same thread as your game logic). Also AFAIK WebAudio doesn't currently require a user gesture in chromium (though may in the future). Maybe you're talking about other ways of playing audio? /cc @rtoy |
Now the AudioWorklet spec has become more than a proposal. Also we recently added the FWIW, there has been an attempt to support BaseAudioContext in worker scope, but it was pushed back to V2 spec. I believe this is the solution for @AshleyScirra's scenario. I am aware that it is really important for game engine developers, so I would love to support it sooner than later. |
The difficult thing about audio playback is that while AudioContext works for a lot of things, it is designed around fully-decoded, fully-decompressed audio buffers. This is unsuitable for long music tracks, where HTMLAudioElement has a nice streaming capability. However being a DOM element it's difficult to see how it would ever run in a worker. Perhaps one day MediaStreams will even be transferrable to a worker, but even then you still need a play() call on a DOM element that would have to obey user gesture restrictions. |
I've posted my proposal here: https://github.com/dtapuska/useractivation |
Add a variable on the navigator object to query whether the frame has seen a user activation ever. The postMessage part of the proposal will be done in a separate patch, this change is limited to just adding the object definition and exposing it on navigator. https://github.com/dtapuska/useractivation whatwg/html#1983 BUG=846858 Change-Id: I6ca4c80f4096bfae9ca13b175b46df6b4486a6dd
Thanks! I'm pretty happy with the proposal myself. And I remain hopeful that we can add something here even before we fix the interop problems around user activation (#1903); the basic functionality, of knowing whether user activation is currently in progress, or has at some point happened, should survive any future modifications. Looking back at earlier parts of the thread, it seems like some of @annevk's concerns were around how this fits with postMessage and message-passing. I think @dtapuska's proposal addresses that pretty elegantly, with the opt-in at message time capturing the state of the window posting the message. I'm curious to hear others' thoughts. |
As long as folks are convinced it's really best for this to be sender opt-in, then I'm happy with @dtapuska's proposal! |
Add a variable on the navigator object to query whether the frame has seen a user activation ever. The postMessage part of the proposal will be done in a separate patch, this change is limited to just adding the object definition and exposing it on navigator. https://github.com/dtapuska/useractivation whatwg/html#1983 BUG=846858 Change-Id: I6ca4c80f4096bfae9ca13b175b46df6b4486a6dd
Add a variable on the navigator object to query whether the frame has seen a user activation ever. The postMessage part of the proposal will be done in a separate patch, this change is limited to just adding the object definition and exposing it on navigator. https://github.com/dtapuska/useractivation whatwg/html#1983 BUG=846858 Change-Id: I6ca4c80f4096bfae9ca13b175b46df6b4486a6dd
Add a variable on the navigator object to query whether the frame has seen a user activation ever. The postMessage part of the proposal will be done in a separate patch, this change is limited to just adding the object definition and exposing it on navigator. https://github.com/dtapuska/useractivation whatwg/html#1983 BUG=846858 Change-Id: I6ca4c80f4096bfae9ca13b175b46df6b4486a6dd
Add a variable on the navigator object to query whether the frame has seen a user activation ever. The postMessage part of the proposal will be done in a separate patch, this change is limited to just adding the object definition and exposing it on navigator. https://github.com/dtapuska/useractivation whatwg/html#1983 BUG=846858 Change-Id: I6ca4c80f4096bfae9ca13b175b46df6b4486a6dd
Add a variable on the navigator object to query whether the frame has seen a user activation ever. The postMessage part of the proposal will be done in a separate patch, this change is limited to just adding the object definition and exposing it on navigator. https://github.com/dtapuska/useractivation whatwg/html#1983 BUG=846858 Change-Id: I6ca4c80f4096bfae9ca13b175b46df6b4486a6dd
Add a variable on the navigator object to query whether the frame has seen a user activation ever. The postMessage part of the proposal will be done in a separate patch, this change is limited to just adding the object definition and exposing it on navigator. https://github.com/dtapuska/useractivation whatwg/html#1983 BUG=846858 Change-Id: I6ca4c80f4096bfae9ca13b175b46df6b4486a6dd Reviewed-on: https://chromium-review.googlesource.com/1076979 Commit-Queue: Dave Tapuska <dtapuska@chromium.org> Reviewed-by: Rick Byers <rbyers@chromium.org> Reviewed-by: Mustaq Ahmed <mustaq@chromium.org> Cr-Commit-Position: refs/heads/master@{#572847}
Add a variable on the navigator object to query whether the frame has seen a user activation ever. The postMessage part of the proposal will be done in a separate patch, this change is limited to just adding the object definition and exposing it on navigator. https://github.com/dtapuska/useractivation whatwg/html#1983 BUG=846858 Change-Id: I6ca4c80f4096bfae9ca13b175b46df6b4486a6dd Reviewed-on: https://chromium-review.googlesource.com/1076979 Commit-Queue: Dave Tapuska <dtapuska@chromium.org> Reviewed-by: Rick Byers <rbyers@chromium.org> Reviewed-by: Mustaq Ahmed <mustaq@chromium.org> Cr-Commit-Position: refs/heads/master@{#572847}
Add a variable on the navigator object to query whether the frame has seen a user activation ever. The postMessage part of the proposal will be done in a separate patch, this change is limited to just adding the object definition and exposing it on navigator. https://github.com/dtapuska/useractivation whatwg/html#1983 BUG=846858 Change-Id: I6ca4c80f4096bfae9ca13b175b46df6b4486a6dd Reviewed-on: https://chromium-review.googlesource.com/1076979 Commit-Queue: Dave Tapuska <dtapuska@chromium.org> Reviewed-by: Rick Byers <rbyers@chromium.org> Reviewed-by: Mustaq Ahmed <mustaq@chromium.org> Cr-Commit-Position: refs/heads/master@{#572847}
…as seen a user gesture., a=testonly Automatic update from web-platform-testsAdd an API to query whether the window has seen a user gesture. Add a variable on the navigator object to query whether the frame has seen a user activation ever. The postMessage part of the proposal will be done in a separate patch, this change is limited to just adding the object definition and exposing it on navigator. https://github.com/dtapuska/useractivation whatwg/html#1983 BUG=846858 Change-Id: I6ca4c80f4096bfae9ca13b175b46df6b4486a6dd Reviewed-on: https://chromium-review.googlesource.com/1076979 Commit-Queue: Dave Tapuska <dtapuska@chromium.org> Reviewed-by: Rick Byers <rbyers@chromium.org> Reviewed-by: Mustaq Ahmed <mustaq@chromium.org> Cr-Commit-Position: refs/heads/master@{#572847} -- wpt-commits: dfca5197519caef6c189636b5d80b33e3424e91e wpt-pr: 11361
Add an API to query user activation state on a posted message event. Add includeUserActivation attribute on the WindowPostMessageOptions so that indication of user gesture behavior can be opted in. https://github.com/dtapuska/useractivation whatwg/html#1983 BUG=846858 Change-Id: I2459b21004afbe00c41ddf992533c60728768bb4
Add an API to query user activation state on a posted message event. Add includeUserActivation attribute on the WindowPostMessageOptions so that indication of user gesture behavior can be opted in. https://github.com/dtapuska/useractivation whatwg/html#1983 BUG=846858 Change-Id: I2459b21004afbe00c41ddf992533c60728768bb4
Add an API to query user activation state on a posted message event. Add includeUserActivation attribute on the WindowPostMessageOptions so that indication of user gesture behavior can be opted in. https://github.com/dtapuska/useractivation whatwg/html#1983 BUG=846858 Change-Id: I2459b21004afbe00c41ddf992533c60728768bb4
Add an API to query user activation state on a posted message event. Add includeUserActivation attribute on the WindowPostMessageOptions so that indication of user gesture behavior can be opted in. https://github.com/dtapuska/useractivation whatwg/html#1983 BUG=846858 Change-Id: I2459b21004afbe00c41ddf992533c60728768bb4
Add an API to query user activation state on a posted message event. Add includeUserActivation attribute on the WindowPostMessageOptions so that indication of user gesture behavior can be opted in. https://github.com/dtapuska/useractivation whatwg/html#1983 BUG=846858 Change-Id: I2459b21004afbe00c41ddf992533c60728768bb4
Add an API to query user activation state on a posted message event. Add includeUserActivation attribute on the WindowPostMessageOptions so that indication of user gesture behavior can be opted in. https://github.com/dtapuska/useractivation whatwg/html#1983 BUG=846858 Change-Id: I2459b21004afbe00c41ddf992533c60728768bb4
Add an API to query user activation state on a posted message event. Add includeUserActivation attribute on the WindowPostMessageOptions so that indication of user gesture behavior can be opted in. https://github.com/dtapuska/useractivation whatwg/html#1983 BUG=846858 Change-Id: I2459b21004afbe00c41ddf992533c60728768bb4
Add an API to query user activation state on a posted message event. Add includeUserActivation attribute on the WindowPostMessageOptions so that indication of user gesture behavior can be opted in. https://github.com/dtapuska/useractivation whatwg/html#1983 BUG=846858 Change-Id: I2459b21004afbe00c41ddf992533c60728768bb4
Add an API to query user activation state on a posted message event. Add includeUserActivation attribute on the WindowPostMessageOptions so that indication of user gesture behavior can be opted in. https://github.com/dtapuska/useractivation whatwg/html#1983 BUG=846858 TBR=mkwst@chromium.org Change-Id: I2459b21004afbe00c41ddf992533c60728768bb4 Reviewed-on: https://chromium-review.googlesource.com/1131558 Commit-Queue: Dave Tapuska <dtapuska@chromium.org> Reviewed-by: Ken Buchanan <kenrb@chromium.org> Reviewed-by: Marijn Kruisselbrink <mek@chromium.org> Cr-Commit-Position: refs/heads/master@{#579398}
Add an API to query user activation state on a posted message event. Add includeUserActivation attribute on the WindowPostMessageOptions so that indication of user gesture behavior can be opted in. https://github.com/dtapuska/useractivation whatwg/html#1983 BUG=846858 TBR=mkwst@chromium.org Change-Id: I2459b21004afbe00c41ddf992533c60728768bb4 Reviewed-on: https://chromium-review.googlesource.com/1131558 Commit-Queue: Dave Tapuska <dtapuska@chromium.org> Reviewed-by: Ken Buchanan <kenrb@chromium.org> Reviewed-by: Marijn Kruisselbrink <mek@chromium.org> Cr-Commit-Position: refs/heads/master@{#579398}
Add an API to query user activation state on a posted message event. Add includeUserActivation attribute on the WindowPostMessageOptions so that indication of user gesture behavior can be opted in. https://github.com/dtapuska/useractivation whatwg/html#1983 BUG=846858 TBR=mkwst@chromium.org Change-Id: I2459b21004afbe00c41ddf992533c60728768bb4 Reviewed-on: https://chromium-review.googlesource.com/1131558 Commit-Queue: Dave Tapuska <dtapuska@chromium.org> Reviewed-by: Ken Buchanan <kenrb@chromium.org> Reviewed-by: Marijn Kruisselbrink <mek@chromium.org> Cr-Commit-Position: refs/heads/master@{#579398}
…t, a=testonly Automatic update from web-platform-testsAdd UserActivation member to MessageEvent Add an API to query user activation state on a posted message event. Add includeUserActivation attribute on the WindowPostMessageOptions so that indication of user gesture behavior can be opted in. https://github.com/dtapuska/useractivation whatwg/html#1983 BUG=846858 TBR=mkwst@chromium.org Change-Id: I2459b21004afbe00c41ddf992533c60728768bb4 Reviewed-on: https://chromium-review.googlesource.com/1131558 Commit-Queue: Dave Tapuska <dtapuska@chromium.org> Reviewed-by: Ken Buchanan <kenrb@chromium.org> Reviewed-by: Marijn Kruisselbrink <mek@chromium.org> Cr-Commit-Position: refs/heads/master@{#579398} -- wpt-commits: 8a1d5c110779c525257fe2305ba7a21ae6e969e6 wpt-pr: 12157
…t, a=testonly Automatic update from web-platform-testsAdd UserActivation member to MessageEvent Add an API to query user activation state on a posted message event. Add includeUserActivation attribute on the WindowPostMessageOptions so that indication of user gesture behavior can be opted in. https://github.com/dtapuska/useractivation whatwg/html#1983 BUG=846858 TBR=mkwst@chromium.org Change-Id: I2459b21004afbe00c41ddf992533c60728768bb4 Reviewed-on: https://chromium-review.googlesource.com/1131558 Commit-Queue: Dave Tapuska <dtapuska@chromium.org> Reviewed-by: Ken Buchanan <kenrb@chromium.org> Reviewed-by: Marijn Kruisselbrink <mek@chromium.org> Cr-Commit-Position: refs/heads/master@{#579398} -- wpt-commits: 8a1d5c110779c525257fe2305ba7a21ae6e969e6 wpt-pr: 12157
…as seen a user gesture., a=testonly Automatic update from web-platform-testsAdd an API to query whether the window has seen a user gesture. Add a variable on the navigator object to query whether the frame has seen a user activation ever. The postMessage part of the proposal will be done in a separate patch, this change is limited to just adding the object definition and exposing it on navigator. https://github.com/dtapuska/useractivation whatwg/html#1983 BUG=846858 Change-Id: I6ca4c80f4096bfae9ca13b175b46df6b4486a6dd Reviewed-on: https://chromium-review.googlesource.com/1076979 Commit-Queue: Dave Tapuska <dtapuskachromium.org> Reviewed-by: Rick Byers <rbyerschromium.org> Reviewed-by: Mustaq Ahmed <mustaqchromium.org> Cr-Commit-Position: refs/heads/master{#572847} -- wpt-commits: dfca5197519caef6c189636b5d80b33e3424e91e wpt-pr: 11361 UltraBlame original commit: 6ca48fa9e7f0348e0c84196f401467f3afcc5835
…as seen a user gesture., a=testonly Automatic update from web-platform-testsAdd an API to query whether the window has seen a user gesture. Add a variable on the navigator object to query whether the frame has seen a user activation ever. The postMessage part of the proposal will be done in a separate patch, this change is limited to just adding the object definition and exposing it on navigator. https://github.com/dtapuska/useractivation whatwg/html#1983 BUG=846858 Change-Id: I6ca4c80f4096bfae9ca13b175b46df6b4486a6dd Reviewed-on: https://chromium-review.googlesource.com/1076979 Commit-Queue: Dave Tapuska <dtapuskachromium.org> Reviewed-by: Rick Byers <rbyerschromium.org> Reviewed-by: Mustaq Ahmed <mustaqchromium.org> Cr-Commit-Position: refs/heads/master{#572847} -- wpt-commits: dfca5197519caef6c189636b5d80b33e3424e91e wpt-pr: 11361 UltraBlame original commit: 6ca48fa9e7f0348e0c84196f401467f3afcc5835
…t, a=testonly Automatic update from web-platform-testsAdd UserActivation member to MessageEvent Add an API to query user activation state on a posted message event. Add includeUserActivation attribute on the WindowPostMessageOptions so that indication of user gesture behavior can be opted in. https://github.com/dtapuska/useractivation whatwg/html#1983 BUG=846858 TBR=mkwstchromium.org Change-Id: I2459b21004afbe00c41ddf992533c60728768bb4 Reviewed-on: https://chromium-review.googlesource.com/1131558 Commit-Queue: Dave Tapuska <dtapuskachromium.org> Reviewed-by: Ken Buchanan <kenrbchromium.org> Reviewed-by: Marijn Kruisselbrink <mekchromium.org> Cr-Commit-Position: refs/heads/master{#579398} -- wpt-commits: 8a1d5c110779c525257fe2305ba7a21ae6e969e6 wpt-pr: 12157 UltraBlame original commit: 81d76d4b48a5764ebf503172672b563f1f655595
…as seen a user gesture., a=testonly Automatic update from web-platform-testsAdd an API to query whether the window has seen a user gesture. Add a variable on the navigator object to query whether the frame has seen a user activation ever. The postMessage part of the proposal will be done in a separate patch, this change is limited to just adding the object definition and exposing it on navigator. https://github.com/dtapuska/useractivation whatwg/html#1983 BUG=846858 Change-Id: I6ca4c80f4096bfae9ca13b175b46df6b4486a6dd Reviewed-on: https://chromium-review.googlesource.com/1076979 Commit-Queue: Dave Tapuska <dtapuskachromium.org> Reviewed-by: Rick Byers <rbyerschromium.org> Reviewed-by: Mustaq Ahmed <mustaqchromium.org> Cr-Commit-Position: refs/heads/master{#572847} -- wpt-commits: dfca5197519caef6c189636b5d80b33e3424e91e wpt-pr: 11361 UltraBlame original commit: 6ca48fa9e7f0348e0c84196f401467f3afcc5835
…t, a=testonly Automatic update from web-platform-testsAdd UserActivation member to MessageEvent Add an API to query user activation state on a posted message event. Add includeUserActivation attribute on the WindowPostMessageOptions so that indication of user gesture behavior can be opted in. https://github.com/dtapuska/useractivation whatwg/html#1983 BUG=846858 TBR=mkwstchromium.org Change-Id: I2459b21004afbe00c41ddf992533c60728768bb4 Reviewed-on: https://chromium-review.googlesource.com/1131558 Commit-Queue: Dave Tapuska <dtapuskachromium.org> Reviewed-by: Ken Buchanan <kenrbchromium.org> Reviewed-by: Marijn Kruisselbrink <mekchromium.org> Cr-Commit-Position: refs/heads/master{#579398} -- wpt-commits: 8a1d5c110779c525257fe2305ba7a21ae6e969e6 wpt-pr: 12157 UltraBlame original commit: 81d76d4b48a5764ebf503172672b563f1f655595
…t, a=testonly Automatic update from web-platform-testsAdd UserActivation member to MessageEvent Add an API to query user activation state on a posted message event. Add includeUserActivation attribute on the WindowPostMessageOptions so that indication of user gesture behavior can be opted in. https://github.com/dtapuska/useractivation whatwg/html#1983 BUG=846858 TBR=mkwstchromium.org Change-Id: I2459b21004afbe00c41ddf992533c60728768bb4 Reviewed-on: https://chromium-review.googlesource.com/1131558 Commit-Queue: Dave Tapuska <dtapuskachromium.org> Reviewed-by: Ken Buchanan <kenrbchromium.org> Reviewed-by: Marijn Kruisselbrink <mekchromium.org> Cr-Commit-Position: refs/heads/master{#579398} -- wpt-commits: 8a1d5c110779c525257fe2305ba7a21ae6e969e6 wpt-pr: 12157 UltraBlame original commit: 81d76d4b48a5764ebf503172672b563f1f655595
This allows querying both sticky and transient user activation state. Fixes #4008. Closes #4009 by superseding it. See #1983 (which remains open) and https://github.com/dtapuska/useractivation for another related API proposal, for sending user activation state along with message events. Co-authored-by: Dave Tapuska <dtapuska@chromium.org>
Let's consider this resolved. If there's still a need for message-event API that can be discussed in a new issue as a lot of things changed since 2016. |
The triggered by user activation logic allows for this state to flow between cross-origin iframes via postMessage. Unfortunately there's no good way for script to query whether it's currently in this state.
For example script in a trusted frame may want to respond to requests from an untrusted iframe (such as navigating to a new URL) only when the request from the iframe was initiated as a result of a user activation.
That is to say, there's no good reason the "triggered by user activation" logic should be available only to the user agent, script in other frames might want to depend on it for the exact same reasons. There's some discussion here, here and here about why this is particularly important for AMP. Today they're hacking around this in Chrome by attempting to write to the clipboard and seeing if that's successful to sniff that they're currently in the context of a user gesture. This is unfortunate because it potentially clobbers the clipboard and isn't necessarily interoperable. /cc @dvoytenko @cramforce.
Should we just add a boolean property like
navigator.triggeredByUserActivation
? Or should we perhaps defineMessageEvent.isTrusted
to be set to true when the script that invokedpostMessage
was itself triggered by user activation?The text was updated successfully, but these errors were encountered: