[v1.4] 压缩 ts.worker.js 至 4MB 以通过 AMO 验证,修复 MV3 background permission 错误#1221
Merged
CodFrm merged 37 commits intoscriptscat:release/v1.4from Mar 29, 2026
Merged
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
7ae0298 to
7bfacbb
Compare
CodFrm
reviewed
Mar 28, 2026
Collaborator
Author
There was a problem hiding this comment.
不是 混淆代码 是 极小化
代码是 decompress 的 algorithm
Collaborator
Author
There was a problem hiding this comment.
Contributor
There was a problem hiding this comment.
Pull request overview
该 PR 面向 Firefox AMO 上架限制与 Firefox MV3 兼容性问题:通过在 Rspack 构建阶段压缩 Monaco 的 ts.worker.js 以规避单文件大小限制,并移除/规避 Firefox MV3 下不支持的 background permission 检查,避免运行时报错。
Changes:
- 新增
ZipExecutionPlugin,在构建时对ts.worker.js做字符串抽取 + deflateRaw 压缩,并在 Worker 启动时原生 inflate 解压加载。 - 调整 Rspack 压缩输出目标至 ES2022,并将新插件接入构建流程。
- Firefox 打包与前端 UI 移除/隐藏
backgroundpermission 相关检查与交互,避免 Firefox MV3 不支持导致的错误。
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/pages/components/RuntimeSetting/index.tsx | Firefox 下隐藏后台权限开关,并在逻辑层跳过 background permission 检查 |
| scripts/pack.js | Firefox 打包时移除 background optional permission,补充 AMO 相关字段,调整打包包含文件 |
| rspack.config.ts | 接入 ZipExecutionPlugin,并将 minimizer 的 ecma 目标提升到 2022 |
| rspack-plugins/ZipExecutionPlugin.ts | 新增:构建期压缩并包装 ts.worker.js 的核心实现 |
| package.json | 新增构建期依赖 acorn、magic-string |
| pnpm-lock.yaml | 锁文件随依赖变更更新 |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.


压缩 ts.worker.js 绕过 AMO 5MB 限制,修正 Firefox MV3 permission 错误
问题背景
Firefox MV3 扩充套件上架至 addons.mozilla.org (AMO) 时遭遇两个阻断性问题:
ts.worker.js超过 5MB 限制:Monaco Editor 的 TypeScript Worker 打包后约 5.9MB,超出 Mozilla 单档上限,导致 AMO 验证失败。worker-src blob::无法透过 Blob URL 动态建立 Worker,排除了原本的绕过方案。backgroundpermission 检查报错:Firefox MV3 不支援backgroundpermission,相关检查会抛出错误。解决方案
1. 新增
ZipExecutionPlugin(核心改动)在 Rspack 打包阶段新增自订插件
rspack-plugins/ZipExecutionPlugin.ts:ts.worker.js的 ASTeval或blob:压缩效果:5.9MB → ~3.8MB,低于 AMO 的 5MB 限制,且完全符合 Firefox MV3 的 CSP 规范。
2. 调整 Rspack 打包设定(
rspack.config.ts)ZipExecutionPlugin至打包流程3. Firefox 专用打包修正(
scripts/pack.js)data_collection_permissions字段(AMO 审核必要项目)backgroundpermission 的检查(Firefox MV3 不支援此 permission)4. UI 层移除 background permission 检查(
RuntimeSetting/index.tsx)backgroundpermission 的检查逻辑,避免在 Firefox 上报错修改档案一览
rspack-plugins/ZipExecutionPlugin.tsrspack.config.tsscripts/pack.jssrc/pages/components/RuntimeSetting/index.tsxbackgroundpermission UI 检查package.jsonacorn、magic-string依赖pnpm-lock.yaml测试结果
备注