stockfish.js icon indicating copy to clipboard operation
stockfish.js copied to clipboard

Unable to create stockfish object

Open jeffhc opened this issue 7 years ago • 1 comments

I loaded stockfish through a script tag. Now, when I use var stockfish = new STOCKFISH(), I get the error:

on the web, we need the wasm binary to be preloaded and set on Module['wasmBinary']. emcc.py will do that for you when generating HTML (but not JS)

and also

failed to compile wasm module: abort("on the web, we need the wasm binary to be preloaded and set on Module['wasmBinary']. emcc.py will do that for you when generating HTML (but not JS)") at Error

I'm loading a local stockfish.js script into a local html file. I have also tried loading from a web server. Anyone know what's up?

jeffhc avatar Oct 14 '18 07:10 jeffhc

You're right, the WASM version seems to have broken the script tag option. That might be fixable by compiling it with different flags. I'm not sure.

But it's better to use a Web Worker anyway since it offloads work onto another process.

You can load Stockfish as a Web Worker like so:

var stockfish = new Worker("stockfish.js");
stockfish.onmessage = function onmessage(event) {
    console.log(event.data);
};
stockfish.postMessage("go depth 15");

Web Workers do require a web server though.

nmrugg avatar Oct 15 '18 01:10 nmrugg