Skip to content

fix(`packages): expose built artifact paths for runtime content script registration - #2258

Closed
andoan16 wants to merge 1 commit into
wxt-dev:mainfrom
andoan16:contribai/improve/quality/expose-built-artifact-paths-for-runtime-
Closed

andoan16 wants to merge 1 commit into
wxt-dev:mainfrom
andoan16:contribai/improve/quality/expose-built-artifact-paths-for-runtime-

Conversation

@andoan16

Copy link
Copy Markdown

✨ Code Quality

Problem

Content scripts defined with registration: "runtime" cannot be easily registered via browser.scripting.registerContentScripts() because the post-bundle file paths (JS and CSS) are not exposed to the runtime. The build system knows these paths (used for manifest generation), but they are not accessible when importing the content script module from a background/service worker entrypoint. The defineContentScript function needs to return or expose the output file paths in a format compatible with the WebExtension Scripting API.

Severity: medium
File: ``packages/wxt/src/client/defineContentScript.ts (and related build pipeline files)

Solution

Modify the build process to inject the generated output file paths (js/css arrays) into content script modules when they have registration: "runtime". Update defineContentScript to return an object that includes these paths, or provide a companion export (e.g., import { meta } from "./entrypoints/my.content?registration") that exports the RegisteredContentScript-compatible object. Alternatively, create a runtime registry that maps content script IDs to their built file paths, accessible via a new helper like getContentScriptRegistration(id) that returns { js: string[], css: string[], ... } for use with browser.scripting.registerContentScripts().

Changes

  • packages/wxt/src/client/content-script-registry.ts (new)

Overview

Manual Testing

Related Issue

This PR closes #<issue_number>


🤖 About this PR

This pull request was generated by ContribAI, an AI agent
that helps improve open source projects. The change was:

  1. Discovered by automated code analysis
  2. Generated by AI with context-aware code generation
  3. Self-reviewed by AI quality checks

If you have questions or feedback about this PR, please comment below.
We appreciate your time reviewing this contribution!

Closes #2040

… registration

Content scripts defined with `registration: "runtime"` cannot be easily registered via `browser.scripting.registerContentScripts()` because the post-bundle file paths (JS and CSS) are not exposed to the runtime. The build system knows these paths (used for manifest generation), but they are not accessible when importing the content script module from a background/service worker entrypoint. The `defineContentScript` function needs to return or expose the output file paths in a format compatible with the WebExtension Scripting API.

Affected files: content-script-registry.ts

Signed-off-by: andoan16 <[email protected]>
@andoan16
andoan16 requested a review from aklinker1 as a code owner April 13, 2026 12:37
@netlify

netlify Bot commented Apr 13, 2026 •

Copy link
Copy Markdown

❌ Deploy Preview for creative-fairy-df92c4 failed.

Name Link
🔨 Latest commit f996ebe
🔍 Latest deploy log https://app.netlify.com/projects/creative-fairy-df92c4/deploys/69dce390f52d580008387f99

@github-actions github-actions Bot added the pkg/wxt Includes changes to the `packages/wxt` directory label Apr 13, 2026
@andoan16

Copy link
Copy Markdown
Author

Auto-closed: CI checks failed

The following checks failed: Redirect rules - creative-fairy-df92c4, Header rules - creative-fairy-df92c4, Pages changed - creative-fairy-df92c4

Closing this PR since required CI checks did not pass. Sorry for the inconvenience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg/wxt Includes changes to the `packages/wxt` directory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Register a defined Content Script at runtime

1 participant