fix: Scripts injection for MV2 (#2232)

This commit is contained in:
Patryk Kuniczak
2026-04-13 15:47:24 +02:00
committed by GitHub
parent 225a94199c
commit 4ae6d8135f
2 changed files with 7 additions and 3 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ export default defineConfig({
web_accessible_resources: [
{
resources: ['iframe-src.html', 'unlisted.js'],
matches: ['*://*.google.com/*'],
matches: ['*://*.google.com/*', '*://*.example.com/*'],
},
],
},
+6 -2
View File
@@ -26,7 +26,9 @@ export async function injectScript(
const url = browser.runtime.getURL(path);
const script = document.createElement('script');
if (browser.runtime.getManifest().manifest_version === 2) {
const isManifestV2 = browser.runtime.getManifest().manifest_version === 2;
if (isManifestV2) {
// MV2 requires using an inline script
script.text = await fetch(url).then((res) => res.text());
} else {
@@ -34,7 +36,9 @@ export async function injectScript(
script.src = url;
}
const loadedPromise = makeLoadedPromise(script);
// For MV2: Inline scripts execute synchronously when appended
// For MV3: We need to wait for the load event
const loadedPromise = isManifestV2 ? undefined : makeLoadedPromise(script);
await options?.modifyScript?.(script);