whatwg / html

HTML Standard
https://html.spec.whatwg.org/multipage/
Other
8.15k stars 2.67k forks source link

User Activation: ability to transfer activation to another frame #4364

Closed mustaqahmed closed 3 years ago

mustaqahmed commented 5 years ago

To prove that a simple user activation model works for the web (#1903), Chrome just shipped User Activation v2 in M72 (stable release started 2 weeks ago). We encountered some minor regressions so far, all around the common theme that an activated frame wants to delegate activation-dependent tasks to another frame.

This requirement was not relevant before UAv2 in Chrome, because of render-process-wide visibility of activation state. UAv2 defines the default visibility of a user activation to be all container frames, which exposed those use-cases as regressions.

We need to address this problem now: define a way to change the default visibility of user activation.

Here is our proposal: allow transfer of user activation to a target frame through postMessage() calls.

mustaqahmed commented 5 years ago

Here is the design doc for our proposal.

annevk commented 5 years ago

So we'd end up with both a timeout and forwarding a bit? Seems a bit unfortunate.

cc @smaug----

mustaqahmed commented 5 years ago

Let me clarify the difference between the proposed "transfer" vs the "gesture token forwarding" we (conceptually) have without UAv2. I mentioned "conceptually" here because no browser fully supported it because of the complications involved.

Btw, it doesn't have to be postMessage(). Something like targetwindow.transferActivation() could be an option too, might be even better if we want/have to define it to be synchronous.

annevk commented 5 years ago

Thanks. FWIW, I don't think we want another synchronous communication channel between two places that could be in different processes.

mustaqahmed commented 5 years ago

Sticking to postMessage() seems logical then, because:

mustaqahmed commented 5 years ago

@mounirlamouri suggested window.transferUserActivation() instead, which I think can be asynchronous too.

@annevk, wdyt?

@smaug----: we would love to know your thoughts too.

mounirlamouri commented 5 years ago

Something that was pointed out to me offline is that my proposal assumes that the user activation isn't linked to a scope which may be what Mozilla and Chrome are doing but not what Safari is. Do we see a path forward with some consistency here? Do we want to design an API based on a convergence towards a similar behaviour?

mustaqahmed commented 5 years ago

@mounirlamouri: The transfer idea here could be applied to scoped user activation model too, primarily because the model never really worked consistently with postMessages, even for same-origin frames. If the convergence question here is about the underlying model for user activation, I would suggest #1903 for that discussion.

mustaqahmed commented 5 years ago

I agree with @mounirlamouri that window.transferUserActivation() is a cleaner API, vs postMessage() transfer.

travisleithead commented 5 years ago

So, since this transfer API (whether postMessage or transferUserActivation) requires developer to specificially make the transfer, won't they need an introspection API to know if the given window has activation state at the current moment? (Or are we expecting them to simply always attempt to transfer the activation whether or not they might have it?) Is there a place where the current activation state can be read? (e.g., window.hasActivation or window.hasTransientActivation / hasEverBeenActivated)?

mustaqahmed commented 5 years ago

@travisleithead: we proposed a separate query API for that. We have window.navigator.userActivation returning both sticky (.hasBeenActive) and transient (.isActive) bits (available in Chrome 72).

travisleithead commented 5 years ago

Ah, makes sense. Thanks! https://github.com/dtapuska/useractivation

mustaqahmed commented 3 years ago

Motivated by the feedback from TAG about this proposal, plus a new use-case we want to support, we have switched our focus to an alternate Capability Delegation API (WICG repo, design doc).