How to allow the Windows screensaver to start even if the current HTML page contains a video?

383 Views Asked by At

It is well known that, if a video is currently playing on a HTML page, the Windows screen saver won't start, and this is generally good (see How does YouTube prevent the screensaver from showing up during video playback? (Windows)).

But for our application in an embedded computer / Chrome is kiosk mode, we would like to allow the Windows screen saver to start even if the current HTML page in Chrome contains a playing video, even if it is something like:

<video id="abc"></video>
<script type="text/javascript">
navigator.mediaDevices.getUserMedia({ video: true }).then((stream) => {
    document.getElementById("abc").srcObject = stream; 
});
</script>    

How to enable the screensaver to start? (Or more precisely: how to disable the mechanism that makes that Chrome prevents the screensaver to start when there is a playing video?)

3

There are 3 best solutions below

0
Kunal Chikte On BEST ANSWER

Disabling the screensaver behavior in a web browser is not something that can be controlled directly from a web page due to security and privacy considerations. Preventing the screensaver from starting is typically considered a browser-level feature, and modern web browsers often have built-in mechanisms to prevent the screensaver from activating during video playback for user convenience.

In the case of Chrome, it automatically disables the screensaver while video is playing to provide a better user experience and prevent interruptions during video playback.

If you're running Chrome in kiosk mode on an embedded computer and you want to allow the screensaver to start even when there's video playback, you may need to adjust the settings at the browser or operating system level rather than through the HTML page or JavaScript.

2
KroKing On

There's a very simple workaround for this

Just that you are going to implement your own screensaver, it listens for the mouse timeout (for when the user is not doing any interactions) then all you go to do displaying the screensaver.

Example:
You want it to listen to the actual timeout.
If we assumed that the user's screensaver will start after 30min then...

  • You will listen to a custom mouse timeout after 10min
  • Or make the user pick this option, this will lead to timeout after 40min

Then finally..

  • Remove the Video after these 10min.
  • The actual screensaver start to count the 30min and it will be turned off.

Why does this work?
Because the browser actually prevents such interactions with its Wakelock API.
Only the API provides a release method.

0
matt On

as for preventing disabling the screensaver from a webpage, i know of no such api, nor any flag that could be used to configure chrome

the issue has been raised many times

bugs.chromium.org : Add flag for controlling the blocking of power saving mode when using WebRTC

bugs.launchpad.net : Screen doesn't lock or go to sleep when certain Chrome tabs are open



you could use a chrome extension to launch the windows screen saver or perform other tasks

i have a simple use case extension github : simple-nativemessage - see example directory which allows launching programs with elevated and non-elevated permissions

that combined with stackoverflow : how-to-invoke-the-screen-saver-in-windows-in-c

or stackoverflow : launch-system-screensaver-from-c-sharp

there is also a script along these lines community.spiceworks.com : i-need-the-screensaver-to-not-be-disabled-with-firefox-esr-running