brownhci / WebGazer

WebGazer.js: Scalable Webcam EyeTracking Using User Interactions
https://webgazer.cs.brown.edu
Other
3.51k stars 528 forks source link

Webgazer gives undefined variable to JSON.parse #124

Closed TimS70 closed 4 years ago

TimS70 commented 4 years ago

Thank you guys for maintaining this great library! I am currently learning JS in order to create an Eye-Tracking experiment with webgazer. Forgive me my limited knowledge but I think there is something wrong with the current downloadable version on https://webgazer.cs.brown.edu/ (June 16th 2020).

I run parts of the code from the examples on the webpage to start webgazer. The script is simply activated by a html-button on a php-page.

    //start the webgazer tracker
    webgazer.setRegression('ridge') /* currently must set regression and tracker */
        //.setTracker('clmtrackr')
        .setGazeListener(function(data, clock) {
            //   console.log(data); /* data is an object containing an x and y key which are the x and y prediction coordinates (no bounds limiting) */
            //   console.log(clock); /* elapsed time in milliseconds since webgazer.begin() was called */
        })
        .begin()
        .showPredictionPoints(true); /* shows a square every 100 milliseconds where current prediction is */

}

I get the following error message in the Console. From SO, I learned that there might be a problem giving an undefined variable to JSON.parse.

Uncaught SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse () at loadGlobalData (webgazer.js:10841) at Object.webgazer.begin (webgazer.js:11004) at startTheStudy (main.js:2) at HTMLButtonElement.onclick ((index):26)

When I copy the webgazer code with the help of DevTools from the examples on the website, it works (at least my webcam is activated without error message). Does that mean that there is a bug in the current version? Are the examples up to date and this one not?

Thanks in advance!

xanderkoo commented 4 years ago

Hi, couple questions:

  1. Could you copypaste/screenshot the place in the code where json.parse is being called? I don't see a JSON.parse under loadGlobalData in the webgazer download that you linked.
  2. Could you attach the files that are using webgazer? I'd like to try and replicate the behavior.
  3. Could you also attach the exact copy of webgazer that you're using? I suspect you might not be using the most recent version.

Thanks!

TimS70 commented 4 years ago

Hi @xanderkoo, 1) Here is the JSON.parse - command. At the last DevTool step before the error image

I also wonder why you did not find in the JSON.parse in the webgazer code. This code here is the direct link from big blue Download button on webgazer.cs.brown. I saved this page as .js: image

2 & 3) Originally I tried it in both Firefox and Chrome but now I wonder: I can only replicate the error in Chrome (Version 83.0.4103.106 (64-Bit)). Now, it works in Firefox. I reinstalled Chrome but the error persists. Maybe it is only my weird Chrome version?

The webgazer files are here: Code.zip

xanderkoo commented 4 years ago

The version of webgazer.js you screenshotted is old -- I believe it may have been a caching issue. I recommend navigating back to webgazer, and refreshing the page. If that doesn't work, try clearing your cache. For reference, this is what I see at the same link:

Screen Shot 2020-06-16 at 3 40 13 PM

In fact, may be good for you to clone the repo and re-concatenate the webgazer.js file directly (there are instructions on the readme). It'll make sure that you have the needed dependencies.

Let me know if that works.

Here's a zipped copy of the newer webgazer if you need it. webgazer.js.zip

TimS70 commented 4 years ago

I emptied the cache and just found the code that you described. Now it also works in Chrome.

Thank you very much!