sveltejs / sveltejs/kit

Unable to set response headers for SharedArrayBuffer

Open
#11,293 5 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

vite
Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the bug

I have a project which depends on a library which uses SharedArrayBuffer, but I can't get it to work, and always get this error:
ReferenceError: SharedArrayBuffer is not defined

What I need to do

Set

  • Cross-Origin-Opener-Policy header to same-origin
  • Cross-Origin-Embedder-Policy to require-corp
What I have tried:
  • setting headers in vite.config.js
export default defineConfig({
  server: {
    headers: {
      // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer#security_requirements
      "Cross-Origin-Opener-Policy": "same-origin",
      "Cross-Origin-Embedder-Policy": "require-corp",
    },
  },
  plugins: [sveltekit()],
});
  • Writing a hooks.js file to use custom headers
  • Using a middleware in vite.config.js to set headers
Reproduction

Smallest possible repro:
Live example
Repo

Logs

No response

System Info
1.60.125 Chromium: 119.0.6045.199 (Official Build) (64-bit)
Severity

blocking all usage of SvelteKit

Additional Information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked live example and repository, then inspect vite.config.js, hooks.js, and the attempted middleware setup. Verify how the requested Cross-Origin-Opener-Policy and Cross-Origin-Embedder-Policy headers are handled, and confirm the reproduction no longer reports SharedArrayBuffer as undefined.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.