Tips & Tricks: Ensure Newest File-Versions in Local Debug of PsychoJS-Experiments

Hi,

just wanted to share a quick life-hack for local debugging of Online-Experiment-Development with the PsychoPy-Builder.

If you familiar with the Local Psycho-JS-Debug Feature of the Builder, this could be a way to improve your workflow:
image

I have encountered problems with local-testing of generated PsychoJS-Experiments (eg. after “Export HTML”-Builder export). Personally, I often accidently look at an old tab of the experiment or was testing with an opened web browser but didn’t re-press “Export HTML”/ Saved the Psy-Exp-File with “Generate on Save”-Option. This carelessness is often resulting in fixing bugs that actually aren’t there because in the Builder they are fixed, but the JS was just not regenerated due to user-error. So if you want to have a secure way of local testing, that fetches newly generated files automatically you can use this code snippet in a JS-Code-Component - utilizing livejs.com. The code is only excecuted if you are on “localhost”.

if(window.location.hostname=="localhost")
{
let myScript = document.createElement("script");
myScript.setAttribute("src", "https://livejs.com/live.js");
document.body.appendChild(myScript);
}

This is an easy solution that allows an auto-reload of the browser-tabs, if the local files are changed.

In case you are doing a lot of local debug before syncing with the Pavlovia-Server, this might save you lot of time by reducing the possibility of showing non-recent-versions of the exported JavaScript.

Best,
Luke

2 Likes