wxt-dev/wxt

Register a defined Content Script at runtime

Open

#2,040 建立於 2026年1月15日

在 GitHub 查看
 (4 留言) (0 反應) (0 負責人)TypeScript (9,861 star) (511 fork)user submission
contribution welcomegood first issue

描述

Feature Request

I use defineContentScript() for some Logic behind Feature-Toggles. To dynamically inject them I have set registration: "runtime", as well. When I now try to inject these at runtime using browser.scripting.registerContentScripts() I have to specify paths to css and js artifacts generated from my content script directory (e.g. bundled css files from scss code). This pretty much defeats the purpose of the easy to use wxt build system.

I would like to be able to reference my defined Content Script with variable/import References, for example like this:

// entrypoints/my.content/index.ts
export default defineContentScript({ registration: "runtime", ... })
// entrypoints/background.ts
import myContent from "./entrypoints/my.content";
export default defineBackground(() => {
	browser.scripting.registerContentScripts([myContent]); // <- not possible because types do not match
	// post-bundle information on the script (and its parts) is not exposed

	// ... some time later
	browser.scripting.unregisterContentScripts([myContent]);
});

Is your feature request related to a bug?

"N/A"

What are the alternatives?

Working around this by looking into the built artifacts and specifying every file for every content script manually.

Additional context

貢獻者指南