Skip to content
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

Require transient activation to request lock #350

Open
marcoscaceres opened this issue Sep 28, 2022 · 16 comments · May be fixed by #351
Open

Require transient activation to request lock #350

marcoscaceres opened this issue Sep 28, 2022 · 16 comments · May be fixed by #351
Assignees

Comments

@marcoscaceres
Copy link
Member

Given #326, we should now require transient activation to request a lock. This would match how <video> works, which requires a user to activate "play" to acquire the lock.

@marcoscaceres marcoscaceres changed the title Require transient activation Require transient activation to request lock Sep 28, 2022
@marcoscaceres
Copy link
Member Author

Can anyone come up with any reason to not consume the transient activation? I'm coming up kinda empty.

@marcoscaceres marcoscaceres linked a pull request Sep 28, 2022 that will close this issue
4 tasks
@geoffreygaren
Copy link

Can anyone come up with any reason to not consume the transient activation? I'm coming up kinda empty.

Normally I support consuming transient activation so that a single click on a webpage doesn't turn into a giant explosion of popup windows, prompts, etc.

But in this case I'm not so sure. The downside of doing wake lock and some other thing is not very high. You can't wake lock twice in an annoying way, like you could with a popup window. And I believe this is how many videoconferencing sites will work: They will have some button like "start call", and when you hit that button, they will want to start a video, request media capture, and do a wake lock. Ideally you would not need to click twice to "start call".

@reillyeon
Copy link
Member

+1 to @geoffreygaren's video conferencing example. It seems likely that sites will want to combine a wake lock with something else, likely more visual like requesting media capture. The wake lock request shouldn't consume the activation.

@marcoscaceres
Copy link
Member Author

Ok, yes... and that's actually the best use case (non-fullscscreen WebRTC) and one I realize now I've hit a lot.

@marcoscaceres
Copy link
Member Author

Ping. Can we please get this moving again?

@reillyeon
Copy link
Member

@marcoscaceres, we have a bit of data from the metrics I added in Chromium issue 1370132 and it appears that about 80% of screen wake lock requests do not have user activation. That appears to make this proposal a pretty big compatibility issue but I tend to agree with you that requiring activation is a decent protection against abuse.

@rakuco, can you draft a specification update which adds an activation requirement and send an "Intent to Deprecate" to blink-dev@ for requesting a screen wake lock without activation?

@reillyeon
Copy link
Member

Using sticky activation for this (at least for requests to reacquire a wake lock) was discussed at the WebApps WG meeting at TPAC 2023. Once the charter updates have been approved let's move forward with discussing the particulars here between the two implementations.

@reillyeon
Copy link
Member

The proposed more complex behavior is:

  1. If the document has transient user activation then allow the request.
  2. If the document has previously acquired a wake lock (and thus has sticky activation due to the requirement above) then allow the request.
  3. Otherwise, reject the request.

@vinhill
Copy link

vinhill commented Sep 19, 2023

What is the reasoning behind requiring transient activation?
I can see use cases where a website might want to request a wake lock without user interaction. For example, during intra-site navigation, after a page reload, or depending on user preference. If a recipe page provides a toggle for keeping the screen on, it seems convenient to restore this user choice on successive page visits.

@vinhill
Copy link

vinhill commented Nov 21, 2023

@rakuco @reillyeon friendly ping about this. We decided to prototype the API in Gecko without requiring transient activation for now.

@reillyeon
Copy link
Member

I'm still not 100% sure that any activation is really required but I'm planning to do another experiment to find out how many wake lock requests have sticky activation, since that seems like a more reasonable requirement.

@marcoscaceres
Copy link
Member Author

Sticky activation might be a good compromise here... I know WebKit also has issues with this (I'll have to dig it up), but it still doesn't feel great that a page can prevent the screen from sleeping without some kind of user gesture first.

@marcoscaceres
Copy link
Member Author

marcoscaceres commented Nov 29, 2023

Ok, yeah, found it:

https://github.com/WebKit/WebKit/blob/b6b74556b8e6ecc165a8e1edb5fc73cc8e5853c2/Source/WebCore/Modules/screen-wake-lock/WakeLock.cpp#L68-L98

Right, we set a flag that "the wake lock became sticky", which is even better: That way, we still require the user activation, but once the wake lock is sticky, we can reapply it.

That solves for all cases, without the wake lock just being able to piggy back on global sticky activation.

(this is a generally nice concept we should add to HTML as it prevents abuse, while allowing APIs to behave as expected without needing to re-acquire user activation every time... they only need it once)

@smaug----
Copy link

So webkit does what was proposed here #350 (comment)
I could live with that, assuming it is web compatible. I think we need some more data on that, unless #350 (comment) already happened.

@reillyeon
Copy link
Member

Agreed at TPAC 2024:

@smaug----
Copy link

There is some web compat risk there, but we'll figure it out once we try the new model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants