hi-ogawa / Stockfish

stockfish-nnue.wasm
https://stockfish-nnue-wasm.vercel.app
GNU General Public License v3.0
97 stars 11 forks source link

​ worker.js onmessage() captured an uncaught exception: TypeError: Failed to execute 'createObjectURL' on 'URL': Overload resolution failed. #5

Closed rosenfeld closed 3 years ago

rosenfeld commented 3 years ago

Hi, I'm trying to get it to work locally so that I could build a tool that would identify the critical moments from a game imported from PGN but I'm having a hard time figuring out how to set it up.

I've copied stockfish.js, stockfish.worker.js and stockfish.wasm locally and used this to try to initialize Stockfish:

fetch('./stockfish.wasm').then(r => r.arrayBuffer()).then(b => {
  const stockfish = new Stockfish({ wasmBinary: b });
});

Then I get this error:

​ worker.js onmessage() captured an uncaught exception: TypeError: Failed to execute 'createObjectURL' on 'URL': Overload resolution failed.

The data passed to onmessage looks like this:

{cmd: "load", urlOrBlob: undefined, wasmMemory: Memory(2048), wasmModule: Module}

The code expects urlOrBlob not to be undefined. What am I missing, please?

Thanks for this project by the way!

hi-ogawa commented 3 years ago

Hey, thanks for using it and sorry for late response.

Regarding your snippet, Stockfish is not a class but just a function returning promise, so something like this should work instead.

fetch('./stockfish.wasm')
  .then(r => r.arrayBuffer())
  .then(b => Stockfish({ wasmBinary: b }))
  .then(stockfish => stockfish.postMessage('uci'))

I tried this code from chrome devtool console on this page https://stockfish-nnue-js.vercel.app and it worked for me.

rosenfeld commented 3 years ago

Thank you! I guess I'm too used to using classes, sorry for that haha