Closed HaNdTriX closed 1 year ago
Unfortunately, due to an issue with chrome, dev mode won't work in manifest v3. You can only use watch and build.
There's been a chromium bug opened here for a while, but no confirmation or movement on it.
Thank you for your reply.
Afaik script-src-elem
CSP strategies do not work in manifest 3.
Nevertheless Websocket connections to localhost will work with the following CSP:
File: manifest.json
{
...
"content_security_policy": {
"extension_pages": "script-src 'self' http://localhost;object-src 'self';"
}
}
This means we could change the DevServer strategy by moving the reload functionality to the static part of the extension (before it was served via http://localhost:5173
). This reload functionality will then connect to the devserver via WebSocket. Depending on the extension context we could change the reload strategy:
background.service_worker
extension messaging and chrome.scripting.executeScript
popup.js
) chrome.runtime.reload()
or HMRchrome.runtime.reload()
, HMR or Service Worker fetch proxy. (It is possible to connect to a Websocket server from the root scope of the serviceworker. Even though this is against the spec.)The issue is that any content_security_policy.extension_pages
definition won't be used at all. You can see in your original manifest that it's not using script-src-elem
, so that's not the issue.
Per https://developer.chrome.com/docs/extensions/mv3/known-issues/ There's a properly tracked issue open here: https://bugs.chromium.org/p/chromium/issues/detail?id=1247690 that I believe will resolve this when fixed. Estimated timeline for it is: "Targeting Canary support before January, 2023"
Really exciting news! That linked issue has been fixed and is available since Chrome 110.0.5480.0!
I've confirmed the existing HMR solution works in manifest V3 on Chrome 111.0.5515.0! 🎉
I am getting the following error:
when:
npm init @samrum/vite-plugin-web-extension@latest
an manifest V3pnpm run serve:chrome
Additional Infos
Chrome Version 105.0.5195.102 (Official Build) (arm64)
orChrome Canary Version 107.0.5299.0 (Official Build) canary (arm64)
@samrum/vite-plugin-web-extension: 2.0.0