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
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
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:
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
orpython3 -m http.server
from the source directory to serve the files. Then you can visithttp://localhost:8080
in your browser to view your webpage locally.