Search code examples
htmlstockfish

Adding headers to http response for Stockfishjs to work


I am trying to write a html page that includes stockfish.js. (My goal is to create a site where yoy can play certain positions against stockfish.)

The problem is that stockfish.js uses SharedArrayBuffer, so when i load the html Firefox-console outputs "ReferenceError: SharedArrayBuffer is not defined".

On the stockfishjs git-page it says that to avoid this problem I need to add "these HTTP headers on the top level response:

Cross-Origin-Embedder-Policy: require-corp

Cross-Origin-Opener-Policy: same-origin

And the following header on the included files:

Cross-Origin-Embedder-Policy: require-corp"

But how do I do that? (I am new to web-developing, and unfamiliar with php. I used py -m server.http to "imitate" a server while i work.)


Solution

  • How you add HTTP headers depends on which HTTP server you are using and/or which server-side programming languages / frameworks you are using.

    The simple HTTP server that comes with Python won't support PHP, so adding PHP directives to an file served from it isn't going to do anything except send some junk to the browser.

    This question covers adding headers using Python, but you would probably be better off duplicating whatever your production environment is going to be so you can test your configuration in development before deploying it.