Repository navigation
Conversation
0.16.7 起 0.16 自身声明了 db.version(18)(防降级),这些用户的 IndexedDB 已是 18, 1.x 挂在 db.version(18).upgrade 上的 migrateToChromeStorage 永远不会触发, 升级后 chrome.storage 为空、脚本全部「消失」,重启扩展也不会重试。 - 迁移改由 migrateChromeStorage 第 2 项按数据触发:chrome.storage 无脚本且 IndexedDB 有脚本时迁移, v17 / v18 两种旧库走同一路径,且不会用旧副本覆盖已迁移用户的数据 - migrateToChromeStorage 改为可等待、失败抛出,迁移项只在成功后记录,失败下次启动重试 - 迁移脚本时保留原 origin(此前误取全局 origin,写成扩展自身的源)
选项页没有调用 migrate(),dao.ts 里的 Dexie 实例未声明任何表结构,
db.table("scripts") 直接抛 InvalidTableError,错误又被吞掉,按钮点了没有任何效果。
改为通过 SystemClient 消息交给 Service Worker 执行迁移,失败时在页面提示错误。
处理函数注册在 service_worker.ts 入口(migrate() 声明表结构的地方),
不放进 SystemService,避免服务层引入 Dexie。
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.
Checklist / 检查清单
N/A — 「修复已提及的问题」:本问题是发 v1.5.0 时自测发现的,没有对应 issue。
背景
Firefox 正式版 AMO listing(
scriptcat)目前最新版本仍是 MV2 的 0.16.15,约 1.27 万日活;1.x(MV3)此前只发到 beta listing。发 v1.5.0 前在 Firefox Nightly 实测「AMO 签名的 0.16.15 永久安装 → 装脚本跑通 → 永久安装 1.5.0 覆盖升级」:
升级后脚本全部消失。IndexedDB
ScriptCat仍完整(v180,scripts / value / resource 都在),但chrome.storage里一个脚本都没有;重启扩展、点「工具 → 数据迁移 → 重试迁移储存引擎」都救不回来。因此 v1.5.0 没有提交 AMO。
原因有两处:
migrateToChromeStorage挂在db.version(18).upgrade()上,只有库版本升到 18 时才执行。但 0.16.7(2025-07-08,
faae3b83「处理扩展降级问题 [BUG] Orion反安裝MV3版本後,安裝MV2無法正常運作 #503」)起 0.16 自身就声明了db.version(18),之后的 0.16 用户库已经是 18,Dexie 不会再调 upgrade。用同版本 Dexie 4.0.10 验证:v17 库 → upgrade 触发;v18 库 → 不触发,再次打开(重启)也不触发。
migrateToChromeStorage(),而选项页从不执行migrate(),dao.ts的 Dexie 实例没有任何表声明,db.table("scripts")立即抛InvalidTableError,又被try/catch吞掉,页面无任何反馈。现有
MigrationSection.test.tsx把@App/app/migrate整个 mock 掉了,所以测试一直是绿的。本次改动
migrateChromeStorage第 2 项):chrome.storage没有脚本、且 IndexedDB 有脚本时迁移;成功后记入migrations,失败抛出、下次启动重试。db.version(18)保留声明,去掉其 upgrade 回调,v17 / v18 两种旧库走同一条路径,不会重复迁移。migrateToChromeStorage改为可等待:await db.open()取代setTimeout(200),错误不再吞掉;迁移成功后照旧打开 v0.17 说明页并重载扩展。origin。此前解构漏了origin,save里取到的是全局origin(扩展自身的chrome-extension:///moz-extension://)。serviceWorker/system/migrateToChromeStorage消息,由 SW 执行;失败时页面提示错误。处理函数注册在
service_worker.ts入口(migrate()声明表结构的地方),不放进SystemService,避免服务层引入 Dexie。fake-indexeddb,供迁移测试使用真实的 IndexedDB 语义;migrate.test.ts会替换 Dexie 的 IndexedDB 来源、打开 Dexie 单例,因此放进 vitest 的ISOLATED列表。实现考虑
db.version(19)再迁移一次:Chrome / Edge 用户早在 0.16 → 1.0 时就迁移过,IndexedDB 里还留着当年的旧副本;按版本号再触发一次会用旧数据覆盖他们现在的脚本。按「
chrome.storage为空」判断,已迁移用户只会跑一次空检查。migrations已是[1],限定首次启动就救不回他们。已知限制
resource表不迁移(与当年 Chrome 0.16 → 1.0 一致),@require/@resource在迁移后重新下载;资源地址已失效的脚本会缺资源。userScripts是可选权限,升级后不会自动授予。1.5.0 会打开开发者模式 / 授权引导页,Popup 有「请求权限」入口,本 PR 不改动。建议审查重点
src/app/migrate.ts的 diff 大部分是去掉setTimeout包裹后的整体缩进,建议用「Hide whitespace」(?w=1)查看,实际改动约 40 行。migrateChromeStorage第 2 项的触发条件:不能误伤已迁移的用户。src/service_worker.ts中registerMigrationApi在 Chrome(offscreen)/ Firefox(event page)两条分支都注册了。验证
pnpm exec vitest run --no-coverage --project isolated src/app/migrate.test.ts:3/3 通过。修复前 v18、v17 两例失败(迁移后 0 个脚本),「已迁移用户不被覆盖」一例修复前后都通过。pnpm exec vitest run --no-coverage --project ui src/pages/options/routes/Tools/sections/MigrationSection.test.tsx:2/2 通过。修复前该文件因页面引入 Dexie 在加载时崩溃。CI=1 pnpm exec vitest run --no-coverage:375/378 文件通过。失败的 3 个是无关 UI 文件(SubscribeTable / Agent Skills / RuleForm),都是负载约 38 时的 850ms 超时,单独重跑 20/20 通过。(不带
CI=1的本地单 worker 全量跑,未改动的 main 上同样有约 100 个文件因chrome.permissions.reset is not a function失败,是既有问题,不是本 PR 引入。)pnpm lint:通过。pnpm run pack产物永久安装覆盖,不预授予任何权限):migrations=[1];addon.reload()后仍为 0。migrations=[1,2],脚本与启用状态、GM 值count=1都迁移过来,打开了 v0.17 说明页;addon.reload()后仍在。授予
userScripts后脚本照常执行,GM 值在迁移值基础上继续累加,@require重新下载成功。chrome.storage中的 script / scriptCode / value 键(脚本数 0),点「重试迁移储存引擎」后脚本恢复。