Skip to content

fix: 深度重构修复 V3 ServiceWorker 崩溃异常与豆瓣最新反爬虫封锁 (0.13.0)#121

Open
ziyangxiami wants to merge 10 commits into
doufen-org:masterfrom
ziyangxiami:master
Open

fix: 深度重构修复 V3 ServiceWorker 崩溃异常与豆瓣最新反爬虫封锁 (0.13.0)#121
ziyangxiami wants to merge 10 commits into
doufen-org:masterfrom
ziyangxiami:master

Conversation

@ziyangxiami

Copy link
Copy Markdown

🔗 问题背景与动机
由于 Chrome 推进扩展 Manifest V3,叠加近期豆瓣严苛的 API 反爬风控与 CDN 图片防盗链机制,导致插件原有架构全线瘫痪。本次 PR 进行了深度重构与底层机制更替,清扫了大量的陈年 Bug,使得插件恢复了稳定运行和所有的核心备份能力。

🛠 核心修复与改动清单

  1. Manifest V3 运行环境与底层隔离异常

    • 打通 UI 与 Backend 瘫痪失联:修复了原有的 ServiceProxy.js 中 CustomEvent 事件转发 event.target 被浏览器原生覆盖导致的 getProperty is not a function 界面挂死问题。同时解除了硬编码白名单、修复了 message.detail 数据多层嵌套解析引发的 UI 调试面板“服务日志”全白空白 Bug。
    • 绕过 documentimport() 禁用墙:MV3 Background Service Worker 不再支持动态加载与 DOM 操作。移除了导致全面罢工的 import is disallowed 报错,并将后台 HTML 解析器替换为由 esbuild 打包注入的轻量级原生引擎 node-html-parser
  2. 豆瓣全面反爬虫封锁突破

    • 重构 Fetch 的跨域凭证传递(致命的 Cookie 丢失):修复了 Service Worker fetch API 默认缺省凭证引发的大量 12871283 及被强制跳转到 sec.douban.com 的封禁。在网络构造函数 getFetchURL 强行包裹 credentials: 'include',确保插件携带本地登录账号状态(dbcl2、ck 等)发起安全的跨域鉴权访问。
    • CDN 图片 418 防盗链绕道:新增 declarativeNetRequest 安全网络拦截规则,指定 *.doubanio.com 图片发出的 Referer 头伪装成 https://m.douban.com/,一举破除了备份面板或网格缩略图上 HTTP 418 I'm a teapot 的图片显示裂图。
    • 移除粗暴的全局 Referer 覆盖:移除了原版 V3 迁移时过度修改所造成的大量接口报错,转为极其精细的正则表达式(Regex Filter)动态分配,从而兼容需要独立 referer 签名的评论与书影音请求。
  3. 历史遗留功能缺陷解决

    • 修复影评无法抓取接口问题:调整原有的旧接口。
    • 修复广播列表缺失问题:修复了因为游标(Cursor / Context)分页参数获取出错导致终身停留在第一页且无法向下遍历的陈年逻辑。

🎉 测试情况

  • 所有书/影/音/游戏/广播等项目均已能够拉取全部分页记录流
  • Service Worker 前后台通信同步 UI 零报错
  • 成功下载、展示豆瓣所有被保护的尺寸缩略图图片

- Replaced global Referer overwrite in background.js with specific endpoint rules
- Added credentials 'include' to fetch in service.js for cross-origin cookies
- Extracted ServiceProxy to handle UI to Background ServiceWorker RPC messaging in MV3
…olation

- Modified service.js to explicitly dispatch CustomEvent('log') via overriding dispatchEvent
- Fixed Property access for 'detail' payload so it transmits over chrome.runtime.Port correctly
- Updated options.js to listen to 'service.addEventListener' instead of 'service.logger.addEventListener'
- status.js: Fixed pagination issue where inclusive max_id caused ConstraintError loop
- review.js: Refactored fetchReview to use fallback DOM selectors (#link-report) and prevent crashes on missing content
- Added html_parser.js (bundled node-html-parser) to replace 'document.implementation.createHTMLDocument' since MV3 ServiceWorkers lack DOM access
- Refactored 'await import()' to static module mapping in service.js because dynamic imports are disallowed on ServiceWorkerGlobalScope
- options.js: Migrated synchronous getter usage (e.g. service.status, service.currentJob) to await getProperty() for real-time MV3 proxy tracking
- ServiceProxy.js: Fixed uncaught TypeErrors generated by Zepto internal reflection correctly resolving non-function EventTarget properties without attempting .apply
- Task.js: Ensure local task name getter value survives JSON serialization crossing the MV3 boundary
- explorer.js: Injected Zepto `$.fn.attr` interceptor to globally rewrite obsolete `/view/subject/m/public/` thumbnail paths to the new active `/view/subject/s/public/` endpoints since old indexedDB data contains stale CDN routes.
…hotlinking

- Added a declarativeNetRequest rule hitting '*.doubanio.com/*' for 'image' and 'xmlhttprequest' types to append 'Referer: https://m.douban.com/'
- Resolves 418 I'm a teapot errors throwing when 'explorer.js' attempts to load backup images from Douban's servers within the Chrome extension background page origin
…ot a function

- Updated 'options.js' event listeners for 'statechange' and 'progress' to explicitly pass the 'service' proxy instance rather than 'event.target'.
- In MV3, 'EventTarget.dispatchEvent' natively overwrites 'event.target' to the internal object bypassing the JS Proxy.
…vent payloads

- Removed the hardcoded whitelist (only forwarding 'progress' and 'statechange') which silently dropped 'log' events sent by the MV3 Service Worker.
- Rewrote the proxy event forwarding to unwrap 'message.detail' properties instead of double-nesting them inside the 'CustomEvent' detail, fixing missing logs rendering inside 'options.js'.
- Bumped the package version from 0.12.2 to 0.13.0 within 'manifest.json' indicating a stable tracker repair release.
- Updated 'README.md' to showcase 0.13.0's MV3 crash fixes, Douban cookie cross-origin routing resolution natively combating 1287 tracking, CDN Image bypassing rules, and removed the resolved tracking bugs.
- Updated internal developer artifact notes detailing the exact solutions for the deep integration bugs between Chrome extension page Service Workers and Douban's CDN.
@yingchen-ye

Copy link
Copy Markdown

感谢!手动加载到浏览器里,备份终于跑出来了

@caiyu711

Copy link
Copy Markdown

太强了!!!!完美可用!!!!

@Seukieee

Copy link
Copy Markdown

书/影/音/游戏记录能正常备份,豆列似乎备份不了

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants