With any method not requiring special permissions. I want to find out if a website can tell if my screen is off.

Can a browser access that information in any way?

closed as off-topic by gnat, TZHX, Robert Harvey, Jules, amon Jul 17 '16 at 12:43

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions asking for assistance in writing or debugging existing code are off-topic on Programmers. These questions can be asked on Stack Overflow if they include the desired behavior, a specific problem or error, and the shortest code necessary to reproduce it in the question itself. See How To Create a Minimal, Complete, and Verifiable Example." – gnat, TZHX, Robert Harvey, Jules, amon
If this question can be reworded to fit the rules in the help center, please edit the question.

  • If you do not need to be 100% sure, only a more or less likely assumption: show a message with a visible 30 seconds countdown to the user "if you can see this, please press ok". Make sure it is hard to find the ok button with the mouse if the screen is off. Should work similar to the way Windows asks you if you can see anything after you changed the display resolution. – Doc Brown Jul 7 '16 at 20:22
  • 5
    Hmm. I'd solve this problem by trying to access the camera and then look for a mirror in the view and see if the screen is in the reflection....... just saying.... – Brian Tompsett - 汤莱恩 Jul 7 '16 at 20:22

The javascript method window.requestAnimationFrame can be used to request a callback before the window (or tab) is next refreshed. This may (in some circumstances) occur less frequently if the browser is able to determine that the window is not visible (the usual suggestion is if it is minimized or if another tab in the same window has the focus), and a script could detect that reduction in frequency. I haven't tested it, but it seems plausible that at least some browsers might also detect the situation where the screen is off (or at least in power-saving mode, which is much easier to determine using standard APIs) and slow down the calls in that case.

Of course, this does not provide conclusive evidence that the screen is off -- the slow down could have occurred for many reasons -- but it could provide a potential hint.

Not the answer you're looking for? Browse other questions tagged or ask your own question.