Skip to content

修正 shouldFnBind 兼容 Proxy Function#985

Merged
CodFrm merged 9 commits into
scriptscat:mainfrom
cyfung1031:fix-sandbox-1400
Nov 20, 2025
Merged

修正 shouldFnBind 兼容 Proxy Function#985
CodFrm merged 9 commits into
scriptscat:mainfrom
cyfung1031:fix-sandbox-1400

Conversation

@cyfung1031

Copy link
Copy Markdown
Collaborator

概述 Descriptions

我似乎又遇到了一个沙盒问题,使用 Bilibili-Evolved 安装插件,下载视频,会出现下面这个错误,看起来是fetch没有.bind

image

https://www.bilibili.com/video/BV1zuxbzFEJd/

一个最小化可复现脚本:

// ==UserScript==
// @name         New Userscript E381-1
// @namespace    https://docs.scriptcat.org/
// @version      0.1.0
// @description  try to take over the world!
// @author       You
// @match        https://www.bilibili.com/video/BV1zuxbzFEJd/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=www.bilibili.com
// @grant        unsafeWindow
// ==/UserScript==

fetch("https://bbs.tampermonkey.net.cn/")

变更内容 Changes

截图 Screenshots

@CodFrm

CodFrm commented Nov 19, 2025

Copy link
Copy Markdown
Member

我这里启用了 AdGuard 就会出现这个问题(扩展拿不到最原始的fetch),关闭这个问题就消失了(拿到了最原始的fetch),这个问题也好奇怪(TM也是如此)

之前也有因为 AdGuard 产生的问题: #773 (comment)

image
image
image

@cyfung1031

cyfung1031 commented Nov 19, 2025

Copy link
Copy Markdown
Collaborator Author

我这里启用了 AdGuard 就会出现这个问题(扩展拿不到最原始的fetch),关闭这个问题就消失了(拿到了最原始的fetch),这个问题也好奇怪(TM也是如此)

之前也有因为 AdGuard 产生的问题: #773 (comment)

image image image

你用这个PR的跑跑看
应该连带 #773 都解决好的

@cyfung1031 cyfung1031 marked this pull request as draft November 19, 2025 10:21
@cyfung1031

Copy link
Copy Markdown
Collaborator Author

先改一下单元测试

@cyfung1031 cyfung1031 marked this pull request as ready for review November 19, 2025 10:59
@cyfung1031

Copy link
Copy Markdown
Collaborator Author

修改完了

@cyfung1031 cyfung1031 added P0 🚑 需要紧急处理的内容 hotfix 需要尽快更新到扩展商店 labels Nov 19, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

此 PR 修复了沙盒环境中无法正确识别被 Proxy 包装的原生函数的问题。当浏览器扩展(如广告拦截器)使用 Proxy 封装原生函数时,shouldFnBind 函数无法正确识别这些函数,导致 Illegal invocation 错误。

主要变更:

  • 重构了原生函数检测逻辑,支持识别 Proxy 包装的原生函数
  • 完善测试覆盖,包括单元测试和集成测试
  • 修正注释中的拼写错误

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/app/service/content/create_context.ts 重构 getNativeCodeSegs 函数返回前缀和后缀,修改 shouldFnBind 以支持检测 Proxy 包装的原生函数
src/app/service/content/create_context.test.ts 新增单元测试验证 shouldFnBind 对 Proxy 函数的处理
src/app/service/content/exec_script.test.ts 更新集成测试,添加 Proxy Function 测试用例,修正注释拼写
tests/vitest.setup.ts 添加 setTimeoutForTest2 作为 Proxy 包装函数的测试桩

Comment thread src/app/service/content/create_context.ts Outdated
Comment thread tests/vitest.setup.ts Outdated
cyfung1031 and others added 2 commits November 20, 2025 12:11
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@CodFrm CodFrm merged commit 9b17387 into scriptscat:main Nov 20, 2025
2 of 3 checks passed
@cyfung1031 cyfung1031 deleted the fix-sandbox-1400 branch December 21, 2025 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotfix 需要尽快更新到扩展商店 P0 🚑 需要紧急处理的内容

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants