MicrosoftEdge / MicrosoftEdge/WebView2Feedback

Playing videos still prevents the system from entering sleep mode or activating the screensaver

Open
#4,957 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PowerShell
Stars
526
Forks
67
PR merge metrics
No merged PRs in 30d

Description

Discussed in https://github.com/MicrosoftEdge/WebView2Feedback/discussions/4956

Originally posted by Taiizor November 29, 2024
Hello,

I am using WebView2 in my WPF project to play a looping video. However, as long as the window remains open, neither the screensaver activates nor does the system go to sleep.

Below is a code snippet I tried as a solution, but it didn't resolve the issue:

[DllImport("user32.dll", SetLastError = true)]
private static extern void SetThreadExecutionState(uint esFlags);

private const uint ES_CONTINUOUS = 0x80000000;
private const uint ES_SYSTEM_REQUIRED = 0x00000001;
private const uint ES_DISPLAY_REQUIRED = 0x00000002;

private void AllowScreenSaver()
{
    SetThreadExecutionState(ES_CONTINUOUS);
}

private void PreventScreenSaver()
{
    SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED);
}

Additionally, I tried using launcher arguments like --disable-background-timer-throttling --disable-renderer-backgrounding --disable-backgrounding-occluded-windows, but these didn’t work either.

Interestingly, the issue is resolved in MpvPlayer by setting the stop-screensaver option to no. When reviewing its code, I noticed that it uses ES_CONTINUOUS.

https://github.com/mpv-player/mpv/blob/a283f66ede58e0182ac8cd4c930238144427fa74/video/out/w32_common.c#L2326

case VOCTRL_KILL_SCREENSAVER:
	w32->disable_screensaver = true;
	SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED);
	return VO_TRUE;
case VOCTRL_RESTORE_SCREENSAVER:
	w32->disable_screensaver = false;
	SetThreadExecutionState(ES_CONTINUOUS);
	return VO_TRUE;

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the behavior in the described WPF project with WebView2 and review the SetThreadExecutionState calls shown in the issue. Compare the behavior with mpv's video/out/w32_common.c handling of VOCTRL_KILL_SCREENSAVER and VOCTRL_RESTORE_SCREENSAVER. Done means identifying why looping video prevents sleep or the screensaver and documenting or validating a supported resolution.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.