| Reference | Downloads | Github

How to get user screen dimension information when running in Pavlovia?

URL of experiment: NA

Description of the problem:

Is it possible to set a specific location for stimuli in an online experiment using the actual dimensions of the participants’ full-screen window?

Many thanks!

I would be very interested in the answer to this…

I’m not sure exactly what you’re aiming for here. The title say how to get screen dimensions (that could be done with some JavaScript code), but the text says set a specific location (which might be done better just using PsychoPy’s units settings).

e.g. if you mean you want the same pixel location regadless of screen, you can do that just by setting pix as the units for the stimulus.

If you’re wanting something to occupy the same fraction of screen, regardless of screen size then I’d suggest using either Height units or Normalized units depending on whether you want flexible aspect ratios or squares.

But if you spell out a bit more what you’re aiming to achieve we could advise better

I interpreted the question as wanting to put something in the same location on the screen irrespective of whether the experiment is running full screen or in a window (as happens if the participant presses the escape key once).

BTW, a related issue is that on a phone the screen height in height units appears to be greater than 1 (maybe around 1.2)

That’s my guess too and then the answer, as I say, is to use height or norm units. I was just trying to determine if there’s a real need to get the screen dimensions. I think the screen dimensions can be accessed using win.size (or with custom JavaScript)

That’s very curious, but wouldn’t be a complete shock at this point to discover that Apple do things differently to other browsers! :wink:

This information helped a lot with getting screen dimensions, thank you! There’s also code template in the Crib sheet that I found very useful, however I have noticed just now that JS logged my monitor information incorrectly (1920x1080 in reality, logged as 1536/864 in the output file, and also in my PsychoPy configuration). Is there any way to change this mismatch?

I wonder if that’s to do with the dimensions of the window before it went into full-sceen mode (assuming it did go into full-screen mode!)

That might also be the cause of Wakefields issue with iOS - maybe it reports the size at a different point (e.g. the size before switching modes) and therefore gets the sizing wrong

Thank you for the quick reply! It went into full-screen mode - I still had the ‘full screen’ box ticked in PsychoPy; trying with an un-ticked ‘full screen’ box and manually-entered dimensions of 1920x1080 still left visible the top edge of my browser and the taskbar (I’m using Chrome and Windows).

Hello Jon! I have just tried the experiment on a different computer which also has a 1920x1080 screen resolution, and it also logged it incorrectly as 1536x864…I was wondering if there would be any way around this issue? I used this code from the Crib sheet to collect the screen information:

var sUsrAg;
var nIdx;
function getBrowserId () {
var browsers = [“MSIE”, “Firefox”, “Safari”, “Chrome”, “Opera”];
sUsrAg = window.navigator.userAgent,
nIdx = browsers.length - 1;
for (nIdx; nIdx > -1 && sUsrAg.indexOf(browsers [nIdx]) === -1; nIdx–);
return browsers[nIdx];

expInfo[‘OS’] = window.navigator.platform;
expInfo[‘browser’] = getBrowserId();
expInfo[‘xResolution’] = screen.width;
expInfo[‘yResolution’] = screen.height;

Google knows more about JS than me :slight_smile: I’m sure it will have ideas of what code to try inserting. All I can imagine is that the value being reported was somehow before switching into fullscreen mode. But I really don’t know JS very well myself so I’m not the person to answer

1 Like

if I set unit to pix, when I run the experiment on Pavlovia (piloting mode) I get Unspecified JavaScript error (which doesn’t occur if I change unit back to heigh).
What else could I do to fix stimuli size (even text height) and position regardless of screen size?

Why do you want units in pix? The size of a pixel depends on the screen resolution as well as the screen dimensions. Height units only depend on screen dimensions.

I apologize, from @jon comment (see quote) I thought that setting pix as unit would have solved the problem.
What unit would you recommend to use? (cm won’t be supported; my guess is norm, by trying it on two monitors it seems to work, can you see any limit to using norm?)

I recommend norm for multi-line text, because it means you can set the wrap width to something that works well for that screen. Height is good for images and shapes because the aspect ratio is maintained.


Got it. Thank you!!

Thanks, you really saved my work!