Closed Bug 1791079 Opened 2 years ago Closed 1 year ago

Add navigator.userActivation API to query user activation state

Categories

(Core :: DOM: Core & HTML, enhancement, P1)

enhancement

Tracking

()

RESOLVED FIXED
120 Branch
Tracking Status
relnote-firefox --- 120+
firefox120 --- fixed

People

(Reporter: mustaq, Assigned: canadahonk)

References

(Blocks 3 open bugs, )

Details

(Keywords: dev-doc-complete, parity-chrome, parity-safari)

Attachments

(1 file)

User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36

Steps to reproduce:

We have seen general interest about this API [1], mainly for sake of WPTs for user activation (which otherwise have to rely on the behavior of dependent APIs like popup or fullscreen).

Note that this is about only the navigator interface part of the state propagation discussion [2]. Here is the PR to the HTML spec [3] for that interface.

[1] https://github.com/whatwg/html/pull/4009#issuecomment-542363760
[2] https://github.com/whatwg/html/issues/1983
[3] https://github.com/whatwg/html/pull/8254

The Bugbug bot thinks this bug should belong to the 'Core::DOM: Core & HTML' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → DOM: Core & HTML
Product: Firefox → Core
Blocks: 1577516

I wonder this should have gone https://testutils.spec.whatwg.org/ if this is for tests.

See also the HTML spec for details:
https://html.spec.whatwg.org/multipage/interaction.html#the-useractivation-interface

All browsers except Firefox have it implemented so this is a cross-browser compat issue:
https://developer.mozilla.org/en-US/docs/Web/API/UserActivation#browser_compatibility

We would also like to see this API for our WebDriver BiDi implementation. Which priority might this implementation get?

Blocks: 1845488
Status: UNCONFIRMED → NEW
Ever confirmed: true
Flags: needinfo?(jjaschke)
Version: Firefox 91 → unspecified

(In reply to Henrik Skupin [:whimboo][⌚️UTC+2] from comment #5)

See also the HTML spec for details:
https://html.spec.whatwg.org/multipage/interaction.html#the-useractivation-interface

All browsers except Firefox have it implemented so this is a cross-browser compat issue:
https://developer.mozilla.org/en-US/docs/Web/API/UserActivation#browser_compatibility

We would also like to see this API for our WebDriver BiDi implementation. Which priority might this implementation get?

Hi Henrik, it's passed the strategic review and scheduled for H2. Do you have more specific timeline that we should try to align better?

Flags: needinfo?(jjaschke) → needinfo?(hskupin)

Thank you for the information Hsin-Yi! No, this is totally fine and we can temporarily mark the test as expected fail until the navigator.userActiviation support has been added. Instead we want to add another test that actually checks the functionality when its enabled and which doesn't use this API.

Flags: needinfo?(hskupin)

This patch doesn't pass all WPT html/user-activation, but that seem more like an implementation issue that is unrelated to the API. e.g. propagating across frames or something like that?

It's also a bit annoying that we already have a class UserActivation that has a bunch of static functions like IsHandlingUserInput. Right now I just turned that class into the DOM class and kept the static methods.

Priority: -- → P1

Hi :canadahonk, please help us drive this cross the completion line, based on Tom's WIPs. Thank you and thanks Tom!

Assignee: nobody → oj
Flags: needinfo?(oj)

Sure! Thanks to Tom for the initial work.

Flags: needinfo?(omedhurst)

Also, the chrome-only document.hasBeenUserGestureActivated/document.hasValidTransientUserGestureActivation should be able to be replaced with this new API if wanted to clean up.

Attachment #9347256 - Attachment description: WIP: Bug 1791079 - Implement the navigator.userActivation API → WIP: Bug 1791079 - Implement User Activation API
Attachment #9347256 - Attachment description: WIP: Bug 1791079 - Implement User Activation API → Bug 1791079 - Implement User Activation API
Status: NEW → ASSIGNED
Keywords: dev-doc-needed
Summary: navigator.userActivation API to query user activation state → Add navigator.userActivation API to query user activation state
Pushed by omedhurst@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/7c84c5fc7d00 Implement User Activation API r=dom-core,webidl,saschanaz,edgar
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/42395 for changes under testing/web-platform/tests

Forgot to add a null check, sorry. Fixed and will reland.

Flags: needinfo?(omedhurst)
Upstream PR was closed without merging
Pushed by omedhurst@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/73919dbff272 Implement User Activation API r=dom-core,webidl,saschanaz,edgar
Upstream PR was closed without merging

Fixed build bust and WPT expectation for that file.

Flags: needinfo?(omedhurst)
Pushed by omedhurst@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/fba49989dde6 Implement User Activation API r=dom-core,webidl,saschanaz,edgar
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 120 Branch
Regressions: 1857798

:oliver is this something worth mentioning in the Fx120 release notes?

Flags: needinfo?(omedhurst)

Yes, I was going to flag relnote on Monday :)

Flags: needinfo?(omedhurst)
Upstream PR merged by moz-wptsync-bot

Release Note Request (optional, but appreciated)
[Why is this notable]: New web API (navigator.userActivation)
[Affects Firefox for Android]: Yes
[Suggested wording]: The User Activation API has been added, allowing JavaScript to check if the user currently is or has been active with navigator.userActivation.
[Links (documentation, blog post, etc)]: https://developer.mozilla.org/en-US/docs/Web/API/UserActivation

relnote-firefox: --- → ?

(In reply to Oliver Medhurst [:canadahonk] from comment #28)

check if the user currently is or has been active with navigator.userActivation.

Sounds a bit confusing to me, it's not really about the user but about the interaction with the page, right? "The user currently is active" sounds like it's tracking physical movement through camera to me.

Sorry, good point, better wording might be "...the user currently is or has been active with the page (clicking, etc) with navigator.userActivation". Dianna would you mind updating this to avoid confusion later? Thank you!

Flags: needinfo?(dsmith)

That sounds better, thanks 👍

Fixed!

Flags: needinfo?(dsmith)

FF120 MDN docs for this can be tracked on https://github.com/mdn/content/issues/29778. Compatibility work already done.

The original API in the explainer was quite different and centered around a use case where a page might want to decide if it should allow an iframe to expand itself by checking if the user had interacted with the iframe. While the docs UserActivation and Navigator.userActivation accurately reflect the specification, they have lost information about use cases where this might be something you want to do - i.e. it is only "if you want to programmatically check for user activation". I think it is useful to expose use cases in docs.

So:

  1. Is the explainer use case still one of interest? If so, would this be done by a message from the iframe, and then doing something like the following to check the frame activation?
     const iframe = document.getElementById('myFrame');
     let userActivation = iframe.contentWindow.navigator.userActivation;
    
    Or is it expected that you'd just check the parent frame navigator and it would show activation of the contained frame too? I.e. how is this really expected to be used now? (example code would be nice!)
  2. Are there any other main use cases we expect this to be used for?
  3. Some of the WPT tests pass for Chrome and not for Firefox, and visa versa https://wpt.fyi/results/html/user-activation?label=master&label=experimental&aligned
    • are these indicative of off-spec behaviour or Firefox bugs?
    • is there something going on here that needs to be captured in docs?

Thanks.

Flags: needinfo?(omedhurst)

Thanks for the MDN work! To answer your questions:

  1. Not really sure to be honest, the explainer is quite outdated. I don't think so. I think the below is the most common use by far.
  2. Some sites use this to check if the user is active and open a popup, play video/audio, etc if so. This is to avoid popup blockers or ensure they are allowed to play video/audio, etc.
  3. These are (niche) webdriver bugs, they do not occur in regular usage and do not need to be documented.

Please also note the includeUserActivation option for postMessage is not implemented or supported as it is non-standard (as of now).

Flags: needinfo?(omedhurst)

Thanks very much Oliver! Very useful to know all this because it means the current docs are largely sufficient. FYI only - work for this done and in review.

Just wanted to add two points from the Chrome side:

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: