From 41833c644da51d05a0c3baeba2d9877b57d42b14 Mon Sep 17 00:00:00 2001 From: Johan Kiviniemi Date: Thu, 19 Jun 2025 12:28:53 +0300 Subject: [PATCH] feat: Remove script element immediately in injectScript Everything seems to work: the script is executed; onload, onerror handlers do the right thing; document.currentScript invoked by the script returns the detached script element. --- packages/wxt/src/utils/inject-script.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/wxt/src/utils/inject-script.ts b/packages/wxt/src/utils/inject-script.ts index 2043e2da8..833b85266 100644 --- a/packages/wxt/src/utils/inject-script.ts +++ b/packages/wxt/src/utils/inject-script.ts @@ -32,11 +32,11 @@ export async function injectScript( script.src = url; } + (document.head ?? document.documentElement).append(script); + if (!options?.keepInDom) { - script.onload = () => script.remove(); + script.remove(); } - - (document.head ?? document.documentElement).append(script); } export interface InjectScriptOptions {