skip to Main Content

I’m trying to run this in my index.html:

<script>
var stockfish = new Worker('./js/stockfish.js');

stockfish.addEventListener('message', function (e) {
  console.log(e.data);
});
 
stockfish.postMessage('uci');
</script>

But I get the following error:

Security error: content located at file:///D:/ChessComparator/index.html cannot load data from file:///D:/ChessComparator/js/stockfish.js.

I cannot run web workers on Chrome and I can’t think of another browser to test this on.

3

Answers


  1. i found that it just doesn’t work in chrome locally by default. how to get it to work on chrome i don’t know, but you can just use safari or firefox

    Login or Signup to reply.
  2. If you need to use web workers with local scripts files, you should use Safari or Firefox. Chrome is the only browser where you can’t do it.

    Before installing other browsers you could try if the script works loaded like this:

    var stockfish = new Worker(URL.createObjectURL(new Blob(["(./js/stockfish.js)()"], {type: 'text/javascript'})));
    
    Login or Signup to reply.
  3. The easiest solution to these sorts of problems is to avoid testing in file URI and other null origins.

    If you just to get it working, try running python -m http.server or python3 -m http.server from the source directory to serve the files. Then you can visit http://localhost:8080 in your browser to view your webpage locally.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search