Skip to content

实现 @run-in / 分离隐身模式 - #384

Merged
CodFrm merged 7 commits into
scriptscat:develop/mv3from
DreamNya:@run-in-/-incognito
May 10, 2025
Merged

CodFrm merged 7 commits into
scriptscat:develop/mv3from
DreamNya:@run-in-/-incognito

Conversation

@DreamNya

@DreamNya DreamNya commented May 8, 2025 •

Copy link
Copy Markdown
Contributor

@run-in api

用于显式声明脚本注入标签类型

  • normal-tabs 注入正常标签
  • incognito-tabs 注入隐身标签

缺省时、同时声明时,既注入正常标签又隐身标签
具体用法见新增示例

TODO

同步更新GM_info

新增 CacheStorage.prototype.clear 方法 清除所有缓存

manifest.json显示声明"incognito": "split"分离浏览器隐身模式时扩展进程及上下文

注:目前隐身模式的chrome.storage操作会影响正常模式

TODO

  • 新增设置,用于用户选择,是否隔离隐身模式扩展存储

package.json新增dev-noMap方法

  • 无SourceMap的development模式
    (已知带SourceMap的dev模式会造成扩展的service_work.js无法完成注册,可能是浏览器限制或bug)

@run-in api 显式声明脚本注入标签类型
 - `normal-tabs` 注入正常标签
 - `incognito-tabs` 注入隐身标签
缺省时、同时声明时,既注入正常标签又隐身标签
具体用法见新增示例

新增 `CacheStorage.prototype.clear` 清除所有缓存

同步更新`GM_info`

`manifest.json`显示声明`"incognito": "split"`分离浏览器隐身模式时扩展进程及上下文

`package.json`新增`dev-noMap`方法
 - 无`SourceMap`的`development`模式
(已知带`SourceMap`的`dev`模式会造成扩展的`service_work.js`无法完成注册,可能是浏览器限制或bug)
Comment thread src/manifest.json
"scripts": ["src/service_worker.js"]
"service_worker": "src/service_worker.js"
},
"incognito": "split",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"incognito": "split"能够隔离正常模式和隐身模式扩展上下文
不添加"incognito"字段,扩展正常模式和隐身模式共用同一个service_worker等上下文,正常模式下的操作能实时影响隐身模式,即使在隐身模式中,扩展也无法直接知道自己在隐身模式中(可能可以通过chrome.tab的运行环境等特殊方法间接判断)

在"incognito": "split"隔离上下文的情况下,带SourceMap的dev模式加载扩展,进入隐身模式service_worker会无法完成注册,产生报错

Service worker registration failed. Status code: 10
Failed to access storage.

我这边100%复现,排查方法service_worker.ts:

  • pack打包扩展后,隐身模式下service_worker正常注册无报错
  • 将main();入口注释、function main()不注释,仍然报错
  • 注释整个function main(),不报错

推测是带SourceMap打包后service_worker文件过大,导致注册失败,不清楚是隐身模式的限制还是浏览器BUG

@CodFrm

CodFrm commented May 9, 2025

Copy link
Copy Markdown
Member

package.json新增dev-noMap方法

会有这个问题吗?一直没遇到唉

@CodFrm
CodFrm merged commit 865e5f6 into scriptscat:develop/mv3 May 10, 2025
@DreamNya
DreamNya deleted the @run-in-/-incognito branch May 10, 2025 09:59
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.

2 participants