How reliable is psychoJS.window._windowAlreadyInFullScreen

I want my experiment to end if the participant exits the fullscreen mode. I’m planning to use something like this code at the end or beginning of every routine:

if not win._windowAlreadyInFullScreen:
    # full screen exited, end experiment.
    quitPsychoJS("The experiment is over.", false);

However, I read this in the core Window source code (

		// (!window.screenTop && !window.screenY) does not work in all browsers on all operating systems (e.g. Chrome on
		// Windows). As far as I can ascertain, as of 2019.08.01 there still does not seem to be a reliable way to
		// test whether the window is already fullscreen.
		// this._windowAlreadyInFullScreen = (!window.screenTop && !window.screenY);

Is it any change as to whether is possible to realiable tell if the web browser window is full screen or not?

You could monitor the keyboard for the Escape key Each Frame. Then a single key press would exit full screen and then immediately exit the experiment.

I have tried implementing your solution wakecarter, but I don’t seem to get it right. I have a piece of code in Each Frame that checks if either Escape or the Up key (for debugging) have been pressed, and if so, changes the variable fullscreen_exited from false to true.

The code works fine for Up key presses (i.e. when I press, fullscreen_exited becomes true). But for Escape, it is as if the first press I make is getting ‘caught’ by the browser without being registered by my code. Fullscreen is exited, but fullscreen_exited stays false. If I then press Esc a second time, it is set to true. I am working on Firefox and with PsychoPy v2021.2.0.

Niclai, if you ended up using wakecarter’s solution, did you run into the same problem, and could you find a solution?