Repository navigation
Conversation
content-script.js runs on every page, and it bundled the perps widget (React UI plus react-dom) eagerly, because strict-CSP pages such as GitHub block a chunk fetched from chrome-extension://. The widget is off by default, so almost every page paid for code it never ran. Build the widget as its own perps-widget entry. On load the content script sends RABBY_INJECT_PERPS_WIDGET; the background checks that the sender is our own content script in a tab's top frame and that the widget is enabled, then injects perps-widget.js with scripting.executeScript (tabs.executeScript on MV2). Extension-injected scripts are not subject to the page's CSP. The entry uses dependOn: 'content-script', so it runs on the content script's webpack runtime, which is already loaded in that isolated world. That is also required by Warden: it inlines module policy only for the content-script and pageProvider runtimes; any other entry looks for warden-policy-runtime.js, which only extension pages load, and throws. build:pro (chrome-mv3 and firefox-mv2): content-script.js 421K -> 251K (-40.5%, gzip 120K -> 67K); the widget is a 170K chunk; total JS unchanged.
Contributor
PR扫描结果依赖变更无依赖变更 |
| // which is also the runtime Warden inlines its module policy for. | ||
| 'perps-widget': { | ||
| import: paths.rootResolve('src/content-script/perps-widget/entry.ts'), | ||
| dependOn: 'content-script', |
Contributor
There was a problem hiding this comment.
Non-blocking/security: @ddddhm1234 Please review the build/supply-chain changes: the widget now has a separate entry sharing the content-script runtime, with a regenerated module policy.
cs1707
marked this pull request as draft
November 4, 2026 07:05
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
perps-widgetentry (src/content-script/perps-widget/entry.ts), declared withdependOn: 'content-script'in both the common and hot webpack configs.content-script.jsno longer bundles the widget. On load it sendsRABBY_INJECT_PERPS_WIDGETto the background.injectPerpsWidgetinsrc/background/index.ts) injectsperps-widget.jsinto the sender's tab withchrome.scripting.executeScript(MV3) orbrowser.tabs.executeScript(MV2). It only does so when:SecSDK/policy.jsonregenerated.Why
content-script.jsruns on every page. It carried the widget's React UI and react-dom eagerly (webpackMode: "eager"), because strict-CSP pages such as Google and GitHub block a chunk fetched fromchrome-extension://. The widget is off by default, so nearly every page load paid for code it never ran. Scripts injected by the extension aren't subject to the page's CSP, so the eager bundling is no longer needed.Results
build:procontent-script.js(chrome-mv3 and firefox-mv2)perps-widget.jsNotes for reviewers
dependOn: Warden inlines its module-require policy only for thecontent-scriptandpageProviderruntimes. That name check is hard-coded inwarden-for-js'sruntime-assets.ts. Any other entry looks forwarden-policy-runtime.js, which only extension pages load, so an independent widget entry threw "Missing webpack require policy" inside the isolated world and never booted. WithdependOn, the widget chunk runs on the content script's webpack runtime, which is already loaded in that isolated world, and Warden inlines its policy there. Shared modules (polyfill, messaging) are not duplicated either;content-script.jsgrows about 7K for the chunk loader and the widget's policy.getPerpsWidgetEnabledcheck.perps-widget, so its vendor code isn't split into a chunk that would never load in the page.activeTab, sotabs.executeScriptwon't work there. Chrome no longer runs MV2 extensions; Firefox MV2 has http/https host permissions.AGENTS.mdsecurity review. It only injects the extension's own file into the requesting tab's top frame, and only when the user setting is on.Testing
yarn typecheckand ESLint on the changed files pass.build:pro(chrome-mv3) andbuild:pro:mv2(firefox-mv2) succeed. In both,content-script.jshas no react-dom andperps-widget.jsis a chunk that starts after the content script's polyfill chunk (222).window.ethereumis Rabby andeth_chainIdanswers.