Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: workaround for the issue with chrome.runtime.getURL introduced in Chrome 130 causing CSP rejecting script due to different origin (GUID instead of chrome extension id) #928

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/smart-bottles-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@crxjs/vite-plugin': major
---

fix: workaround for the issue with chrome.runtime.getURL introduced in Chrome 130 causing CSP rejecting script due to different origin (GUID instead of chrome extension id)
2 changes: 1 addition & 1 deletion packages/vite-plugin/src/client/es/hmr-client-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ declare const __SERVER_PORT__: string

/* -------- REDIRECT FETCH TO THE DEV SERVER ------- */

const ownOrigin = new URL(chrome.runtime.getURL('/')).origin
const ownOrigin = `chrome-extension://${chrome.runtime.id}`;
self.addEventListener('fetch', (fetchEvent) => {
const url = new URL(fetchEvent.request.url)
if (url.origin === ownOrigin) {
Expand Down
12 changes: 6 additions & 6 deletions packages/vite-plugin/src/node/archive/plugin-contentScripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,11 @@ export const pluginContentScripts: CrxPluginFn = ({
resources: ['**/*', '*'],
}

if (browser !== 'firefox') {
// change the extension origin on every reload
// not allowed in FF b/c FF does this by default
war.use_dynamic_url = true
}
// if (browser !== 'firefox') {
// // change the extension origin on every reload
// // not allowed in FF b/c FF does this by default
// war.use_dynamic_url = true
// }

manifest.web_accessible_resources.push(war)
} else {
Expand Down Expand Up @@ -522,7 +522,7 @@ export const pluginContentScripts: CrxPluginFn = ({
| WebAccessibleResourceByMatch = {
matches: script.matches,
resources: [...assets, ...imports],
use_dynamic_url: true,
use_dynamic_url: false,
}

if (css.size)
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-plugin/src/node/defineManifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const defineManifest = (manifest: ManifestV3Export): ManifestV3Export =>
*/
export const defineDynamicResource = ({
matches = ['http://*/*', 'https://*/*'],
use_dynamic_url = true,
use_dynamic_url = false,
}: Omit<
WebAccessibleResourceByMatch,
'resources'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const pluginWebAccessibleResources: CrxPluginFn = () => {
// all resources are web accessible
resources: ['**/*', '*'],
// change the extension origin on every reload
use_dynamic_url: true,
use_dynamic_url: false,
}

if (browser === 'firefox') {
Expand Down Expand Up @@ -163,7 +163,7 @@ export const pluginWebAccessibleResources: CrxPluginFn = () => {
resources: [...assets, ...imports],
use_dynamic_url: isDynamicScript
? dynamicScriptDynamicUrl
: true,
: false,
}

if (isDynamicScript || !injectCss) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Object {
"resources": Array [
"assets/content.js.hash1.js",
],
"use_dynamic_url": true,
"use_dynamic_url": false,
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Object {
"*",
"**/*",
],
"use_dynamic_url": true,
"use_dynamic_url": false,
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Object {
"resources": Array [
"assets/content.ts.hash1.js",
],
"use_dynamic_url": true,
"use_dynamic_url": false,
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Object {
"*",
"**/*",
],
"use_dynamic_url": true,
"use_dynamic_url": false,
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Object {
"resources": Array [
"assets/content.js.hash1.js",
],
"use_dynamic_url": true,
"use_dynamic_url": false,
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Object {
"*",
"**/*",
],
"use_dynamic_url": true,
"use_dynamic_url": false,
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Object {
"assets/declared-script.ts.hash1.js",
"assets/main-world.ts.hash2.js",
],
"use_dynamic_url": true,
"use_dynamic_url": false,
},
Object {
"matches": Array [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Object {
"*",
"**/*",
],
"use_dynamic_url": true,
"use_dynamic_url": false,
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Object {
"assets/index.ts.hash4.js",
"assets/index.ts.hash5.js",
],
"use_dynamic_url": true,
"use_dynamic_url": false,
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Object {
"*",
"**/*",
],
"use_dynamic_url": true,
"use_dynamic_url": false,
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Object {
"assets/index.ts.hash6.js",
"assets/index.ts.hash7.js",
],
"use_dynamic_url": true,
"use_dynamic_url": false,
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Object {
"*",
"**/*",
],
"use_dynamic_url": true,
"use_dynamic_url": false,
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Object {
"resources": Array [
"assets/content.ts.hash2.js",
],
"use_dynamic_url": true,
"use_dynamic_url": false,
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Object {
"*",
"**/*",
],
"use_dynamic_url": true,
"use_dynamic_url": false,
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Object {
"assets/image.hash3.png",
"assets/script.ts.hash4.js",
],
"use_dynamic_url": true,
"use_dynamic_url": false,
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Object {
"*",
"**/*",
],
"use_dynamic_url": true,
"use_dynamic_url": false,
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Object {
"assets/image.hash3.png",
"assets/script.ts.hash4.js",
],
"use_dynamic_url": true,
"use_dynamic_url": false,
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Object {
"*",
"**/*",
],
"use_dynamic_url": true,
"use_dynamic_url": false,
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Object {
"assets/image.hash3.png",
"assets/script.ts.hash4.js",
],
"use_dynamic_url": true,
"use_dynamic_url": false,
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Object {
"*",
"**/*",
],
"use_dynamic_url": true,
"use_dynamic_url": false,
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Object {
"assets/content.tsx.hash2.js",
"assets/vendor.hash3.js",
],
"use_dynamic_url": true,
"use_dynamic_url": false,
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Object {
"*",
"**/*",
],
"use_dynamic_url": true,
"use_dynamic_url": false,
},
],
}
Expand All @@ -46,7 +46,7 @@ Array [
"src/content.tsx-loader.js",
"src/content.tsx.js",
"src/popup.html",
"vendor/chunk-D6CDYV2H.js__v--hash.js",
"vendor/chunk-MPSAKQTA.js__v--hash.js",
"vendor/crx-client-port.js",
"vendor/crx-client-preamble.js",
"vendor/id-__x00__react-jsx-dev-runtime.js",
Expand Down Expand Up @@ -170,15 +170,42 @@ export default App;
var _c;
$RefreshReg$(_c, \\"App\\");
if (import.meta.hot) {
let isReactRefreshBoundary = function(mod) {
if (mod == null || typeof mod !== \\"object\\") {
return false;
}
let hasExports = false;
let areAllExportsComponents = true;
for (const exportName in mod) {
hasExports = true;
if (exportName === \\"__esModule\\") {
continue;
}
const desc = Object.getOwnPropertyDescriptor(mod, exportName);
if (desc && desc.get) {
return false;
}
const exportValue = mod[exportName];
if (!RefreshRuntime.isLikelyComponentType(exportValue)) {
areAllExportsComponents = false;
}
}
return hasExports && areAllExportsComponents;
};
window.$RefreshReg$ = prevRefreshReg;
window.$RefreshSig$ = prevRefreshSig;
import.meta.hot.accept();
if (!window.__vite_plugin_react_timeout) {
window.__vite_plugin_react_timeout = setTimeout(() => {
window.__vite_plugin_react_timeout = 0;
RefreshRuntime.performReactRefresh();
}, 30);
}
import.meta.hot.accept((mod) => {
if (isReactRefreshBoundary(mod)) {
if (!window.__vite_plugin_react_timeout) {
window.__vite_plugin_react_timeout = setTimeout(() => {
window.__vite_plugin_react_timeout = 0;
RefreshRuntime.performReactRefresh();
}, 30);
}
} else {
import.meta.hot.invalidate();
}
});
}
"
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Object {
"resources": Array [
"assets/content.ts.hash1.js",
],
"use_dynamic_url": true,
"use_dynamic_url": false,
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Object {
"*",
"**/*",
],
"use_dynamic_url": true,
"use_dynamic_url": false,
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Object {
"assets/svelte.hash.png",
"assets/vendor.hash.js",
],
"use_dynamic_url": true,
"use_dynamic_url": false,
},
],
}
Expand Down
Loading
Loading