Repository navigation
Headers are not send #22236
Describe the bugI'm working an a browser extension, I'm using Vue + Vite for the web pages. I needed to use OPFS, so I had to set Cross-Origin-Opener-Policy and Cross-Origin-Embedder-Policy. I added this to the server, and it used to work. It seems like it's not working anymore, the html file has it but other files don't. I've checked this, but I'm not using preview #9864 I haven't seen any indication in the doc that the headers should not be always send, the doc is sparse though:
I have this config: // in the plugins:
{
name: 'set-headers',
configurePreviewServer(server) {
server.middlewares.use((req, res, next) => {
res.setHeader("Cross-Origin-Opener-Policy", "same-origin")
res.setHeader("Cross-Origin-Embedder-Policy", "require-corp")
next()
})
}
}
],
// WARN : necessary for wasm SQLite
server: {
headers: {
'Cross-Origin-Opener-Policy': 'same-origin',
'Cross-Origin-Embedder-Policy': 'require-corp',
},
watch: {
ignored: [
// "./src/options/worker.ts",
// "./src/options/worker.js"
],
},
},
optimizeDeps: {
include: [
'vue',
'@vueuse/core',
'webextension-polyfill',
],
exclude: [
'vue-demi',
'@sqlite.org/sqlite-wasm',
'quickjs-emscripten'
],
},Since then, I've updated a few files because I thought the error was from SQLite but it seems it was not. Reproductionhttps://codeberg.org/SoloDeveloping/SemanticNotes Steps to reproduceRun pnpm install, pnpm dev, install the extension, open the sidepanel, open the main extension url, and it does not seem to be working anymore. System InfoSystem:
OS: Windows 10 10.0.19045
Browsers:
Chrome: 147.0.7727.56
Brave 1.89.132 (Build officiel) (64 bits)
Chromium: 147.0.7727.56
Tested on Chrome and Brave.Used Package Managerpnpm LogsIt's present on the html file:
Not present in the main ts file:
Not present in the SQLite file, but requested:
Validations
|
Replies: 4 comments 2 replies
|
Note that the url is in the form http://localhost:3303/@fs/C:/Users/ Not sure it matters since only the html file seem to have it |
|
What you’re seeing is likely the difference between document responses and module/asset requests, especially in an extension/dev-server setup, not just “Vite randomly stopped sending headers”. A few things to separate here:
What I would test next:
So I would not assume “Vite should attach these headers to every file request and if not it’s broken”. |
|
Workaround that works on any version: set them yourself in a middleware plugin so every response gets them. {
name: 'coop-coep'
configureServer(server) {
server.middlewares.use((req, res, next) => {
res.setHeader('Cross-Origin-Opener-Policy', 'same-origin')
res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp')
next()
})
}
}Also worth checking your Vite version, this was fixed so — |
|
Hopefully, it's fixed now, it's been quite some time, I had found a workaround, so I will mark the answer "as answer". |





server.headerson some Vite versions only gets applied to the HTML responses, not to transformed modules or assets. That's exactly the symptom you're describing, index.html has the headers and everything else doesn't.Workaround that works on any version: set them yourself in a middleware plugin so every response gets them.
Also worth checking your Vite version, this was fixed so
server.headerscovers all dev responses on recent releases. If you're already on…