Unspecified JS Error online

URL of experiment: https://gitlab.pavlovia.org/SophsG/mrt

Description of the problem:


I have been having problems getting my experiment online to pavlovia after I managed to get it running smoothly locally on my laptop.

I have tried quite a few different things, so imagine it is probably something to do with the code element I added in the main trials but I can’t figure which element it is. I am not that familiar with psychopy and the different types of code.

When I have piloted the experiment through pavlovia it does show an initialising screen but then it goes straight to an ‘Unspecified JavaScript Error’. When I open up the help screen it shows me this:

null - window.onerror @ core-2020.2.js:1846
FATAL unknown | null - BrowserConsoleAppender.append @ log4javascript.min.js:1
Unchecked runtime.lastError: The message port closed before a response was received.

I have linked my experiment at the start, please let me know if you are not able to see this. Any advice would be really gratefully recieved.

Many thanks,

This error is very difficult to debug, but I have come across three causes:

  1. a text element with a decimal size (e.g. .1) when the units are in pixels.
  2. setting an image as unspecified.
  3. Trying to run an experiment straight after syncing changes when there are lots of resources. To resolve this close and reopen the browser.

Thank you for your reply.

I have tried this and I am still getting an error. However, I uploaded the experiment without my code component and it worked (apart from what the code controlled of course - changing opacity, colour of polygons and click number and time). I then put the code back in and just ‘hashed out’ the JS side of the code and this stopped it working again. I am quite confused by this! Is there anything you can see in my code that would cause this?

Thank you so much, I really appreciate it.

The code in my begin routine box is:

myStimuli = [A_resp, B_resp, C_resp, D_resp]

clickCount = 0
for thisStim in myStimuli:
thisStim.clicked = False

The code in my each fram routine is:

myStimuli = [A_resp, B_resp, C_resp, D_resp]
for thisStim in myStimuli:
if mouse.isPressedIn (thisStim) and thisStim.clicked == False:
thisStim.clicked = True
clickCount += 1

if clickCount >= 2:
    trials.addData('respA', A_resp.clicked)
    trials.addData('respB', B_resp.clicked)
    trials.addData('respC', C_resp.clicked)
    trials.addData('respD', D_resp.clicked)
    continueRoutine = False
if thisStim.clicked == False:
    if thisStim.contains(mouse):
        thisStim.opacity = 0.5
        thisStim.fillColor = 'black'
        thisStim.opacity = 1
        thisStim.fillColor = 'white'

The code in my end routine box:

trials.addData(‘RT’, mouse.time[len(mouse.time)-1])


Hashing doesn’t comment out JavaScript, so that won’t work. Equally, you get an error if you have an auto code tab where all of the Python is hashed out.

I don’t know about thisStime.clicked=False

However, I do know that auto translate doesn’t work for colours.

Have a look at my crib sheet (see pinned post) to see how to define black and white in a both code component. Then try thisStim.fillColor = black (without quotes).

Hi Wakecarter. I’m trying to help Sophie with this, but my skills are left wanting.

The issue I believe is with the looping through the array but not sure how to fix this.

In the python code, Sophie has:

myStimuli = [A_resp, B_resp, C_resp, D_resp]

for thisStim in myStimuli:
if mouse.isPressedIn (thisStim) and thisStim.clicked == False :
thisStim.clicked = True
clickCount += 1

but in the JS this translates to the follow which causes the Unspecified JavaScript error:

myStimuli = [A_resp, B_resp, C_resp, D_resp];
for (var thisStim, _pj_c = 0, _pj_a = myStimuli, _pj_b = _pj_a.length; (_pj_c < _pj_b); _pj_c += 1) {
thisStim = _pj_a[_pj_c];
if ((mouse.isPressedIn(thisStim) && (thisStim.clicked === false))) {
thisStim.clicked = true;
clickCount += 1;

I notice you have a reference in your crib sheet to something that might be relevant:
for i, j in enumerate(distList[‘list’]): - is this a similar issue?

Essentially, the code needs to check if two of four polygons have been clicked on (they change after each click).


I don’t think the issue is with enumerate as per my crib sheet, since that is about the use of enumerate as a Python command.

Is there a mouse component called mouse in this routine or an earlier one?

To try to fix the issue simplify the code until it works. For example, take out the loop and just try recording a click in A_resp

Hi Wakecarter,

The only mouse componenet is in this routine.

I think the problem might be with my polygons (A_resp, B_resp, C_resp, D_resp) and how i’ve included them in my code becasue when I substituted the polygons with an image in the code I didn’t get an error online. It all worked (apart from the changing colour on click componenet).

What would you advise the best way is to define and incorperate clickable polygon stimuli in JS code so it works online?

Many thanks,

Here’s an example of a polygon that translates fine for me. The code comes from https://pavlovia.org/Wake/affect-grid

            lineWidth = 3,
            opacity = 1,
            depth = 1, 
            interpolate = True

P.S. For this to work, I had to use code_JS to define win and a code_both to define some colours. See my crib sheet.

Thank you for all your advice, I’ve managed to fix it by just replacing the polygons with images and using opacity changes instead of colour changes.