Repository navigation
Conversation
✅ Deploy Preview for creative-fairy-df92c4 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Head branch was pushed to by a user without write access
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Register and implement worker rewriting packages/wxt/src/internal/builders/vite/index.ts, packages/wxt/src/internal/builders/vite/plugins/dev-server-workers.ts, packages/wxt/src/internal/builders/vite/plugins/index.ts |
The shared Vite configuration registers the plugin. During development, it matches worker URLs on the dev-server origin and replaces them with blob URLs. Constructor workers use a revoking blob script; URL-module workers buffer early messages and redispatch them after import. |
Verify transformed worker output packages/wxt/src/internal/builders/vite/plugins/__tests__/dev-server-workers.test.ts, packages/wxt/e2e/tests/dev.test.ts |
Unit tests cover replacement behavior, idempotence, and non-matching URLs. End-to-end tests check Chromium output and verify that Firefox and Safari retain worker URLs. |
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix · Severity of issue fixed: Medium
Sequence Diagram(s)
sequenceDiagram
participant ViteBuilder
participant ViteDevServer
participant DevServerWorkersPlugin
participant ChromiumExtensionPage
participant WorkerBlobScript
ViteBuilder->>DevServerWorkersPlugin: register plugin
ViteDevServer->>DevServerWorkersPlugin: provide origin and worker module
DevServerWorkersPlugin-->>ViteDevServer: return transformed module code
ViteDevServer->>ChromiumExtensionPage: serve module with blob URL
ChromiumExtensionPage->>WorkerBlobScript: start worker from blob URL
WorkerBlobScript->>ViteDevServer: import original worker module
Merge Risk: 
Minimal · up to 51dc7
-
No actionable merge-blocking issue was established. The change is ready for normal checks before merge.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Linked Issues check
-
Explanation
Directly linked issue
#2599requires worker URLs on extension pages to be same-origin in dev mode for both?workerand?worker&url. The reviewed head addsdevServerWorkers(packages/wxt/src/internal/builders/vite/plugins/dev-server-workers.ts) and registers it inViteBuilder.getBaseConfig. Forservein non-Firefox and non-Safari builds,replaceDevServerWorkerUrlreplaces the localhostworker_fileURL literal withURL.createObjectURL(new Blob(...)). A blob URL created by an extension page inherits that page'schrome-extension://origin, sonew Worker(blobUrl)is same-origin. The?workerpath (constructor import) revokes its one-shot blob at worker startup. The?worker&urlpath keeps the blob alive and buffers early messages until the dynamicimport()resolves. The e2e test in packages/wxt/e2e/tests/dev.test.ts checks the generated code for both query forms. Production is unchanged because the plugin applies only toserve. Limits of this assessment: static checks confirm the generated code shape and origin behavior. The cross-origin module fetch from the blob worker to the dev server depends on dev server CORS. That runtime behavior is supported only by the author's reported manual Chromium test and the issue's own workaround, not by a test in this PR.
Full details: Out of Scope Changes check
-
Explanation
All changed files map to
#2599or its supporting verification. The plugin source implements the same-origin worker requirement. The barrel export in plugins/index.ts and the registration in builders/vite/index.ts connect the plugin to the Vite build. Unit tests in plugins/tests/dev-server-workers.test.ts cover URL replacement, revocation behavior, and non-matching URLs. The e2e tests in e2e/tests/dev.test.ts cover the Firefox and Safari unchanged path and the Chromium blob path. The?worker&urlmessage buffering is an implementation choice needed so that early messages reach the worker before its module listeners attach. It supports the issue's goal of working reusable worker URLs and is not unrelated behavior. Minor note: the PR description's test command namessrc/core/builders/vite/plugins/__tests__/devServerWorkers.test.ts, while the changed files are undersrc/internal/builders/vite/plugins/__tests__/dev-server-workers.test.ts. This is a documentation inconsistency, not out-of-scope code.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 3 functions across 5 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
|
@coderabbitai review |
Action performed
|
|
@dvd233 GPT review: The overall approach makes sense, especially handling 1. CSP compatibility (potential blocker) The implementation relies on Could you verify this against the default WXT-generated MV3 manifest and provide a reproducible test in a real unpacked Chrome extension? I'd particularly like to confirm that no CSP changes or exceptions are required. 2. Missing real browser integration tests The current E2E tests primarily inspect the transformed worker code rather than actually running it in Chromium. They don't verify that:
A real Chromium MV3 integration test would provide much stronger confidence. 3. Worker location semantics The implementation changes Please consider whether this behavior needs to be preserved or at least explicitly tested/documented. 4. Message event compatibility Replaying buffered messages by constructing new 5. Transform robustness The implementation relies on regexes matching Vite-generated worker wrappers. This is somewhat brittle across Vite versions. Please ensure the tests cover the supported Vite output formats. Also, returning **My main concern is, The Blob-based approach may solve the same-origin issue while introducing a new CSP restriction in MV3. I'd consider this a blocker until the proposed solution is demonstrated to work with the default WXT CSP in a real Chromium extension. Are you able to answer to that? |
Overview
In Chromium dev mode, Vite's
?workerand?worker&urltransforms expose localhost worker URLs to extension pages. Those pages have achrome-extension://origin, so Chrome 148+ rejects the cross-origin dedicated worker URL and can terminate the render process.Add a Chromium-only Vite dev plugin that replaces Vite's generated worker URL with an extension-origin Blob shim while loading the worker module from the dev server. Constructor imports revoke their one-shot Blob URL; reusable
?worker&urlimports keep their URL alive and buffer early messages until the module is ready. Firefox and Safari retain their existing dev-server path because their extension Blob-worker/CSP behavior differs.Production builds are unchanged.
Manual Testing
bun run --filter wxt test run src/core/builders/vite/plugins/__tests__/devServerWorkers.test.ts e2e/tests/dev.test.tsbun run --filter wxt test runbun run --filter wxt check?worker, two reused?worker&urlworkers, immediate messages, and transferredMessagePorts; all returnedready.Related Issue
This PR closes #2599