Skip to content

Register a defined Content Script at runtime #2040

@mptr

Description

@mptr

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions