A Next.js-based chess application with Stockfish integration.
This app is deployed on GitHub Pages here and uses a service worker to add the required security headers for SharedArrayBuffer support. This allows the Stockfish chess engine to work with full functionality even on GitHub Pages.
The app uses a special service worker (coi-serviceworker.js) that adds the following security headers to every response:
Cross-Origin-Embedder-Policy: require-corpCross-Origin-Opener-Policy: same-origin
These headers enable SharedArrayBuffer support, which is required for the WASM-based Stockfish engine.
The service worker works as follows:
- When the page loads for the first time, it registers the service worker
- The service worker adds the required security headers to all responses
- The page reloads automatically
- After the reload, SharedArrayBuffer is available and the WASM Stockfish engine can run
This approach works on all major browsers that support both service workers and WebAssembly threads:
- Chrome/Edge
- Firefox
- Safari (version 15.2+)
npm install
npm run devThis will start the app at http://localhost:9002 where all features will work correctly.
npm run buildPush to the master branch to trigger the GitHub Actions workflow that will deploy to GitHub Pages.
ChessMix © 2025 by Gabriel Dournois is licensed under CC BY-NC-ND 4.0
