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 define MessageEvent.isTrusted to be set to true when the script that invoked postMessage was itself triggered by user activation?
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.isTrustedto be set to true when the script that invokedpostMessagewas itself triggered by user activation?