Repository navigation
fix: keep contextBridge login methods callable instead of proxying them - #3
Merged
Merged
Conversation
This was referenced Oct 26, 2026
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.
现象
点击「添加账号」时按钮无反应,页面顶部出现错误:
根因
src/providers.ts的apiFor()用new Proxy(window.workbuddy, …)按地区改写方法。而contextBridge.exposeInMainWorld暴露的属性是**自身、不可写(writable: false)、不可配置(configurable: false)**的数据属性:按规范,当 target 上的该属性既不可写又不可配置时,
gettrap 必须返回属性本身的值。gettrap 对loginMethods中的方法返回了新包装函数((...args) => target[key](...args, provider)),于是 V8 在调用前就抛错——请求根本没有进入主进程。npm run test:ui不会暴露该问题,因为浏览器测试注入的 mock bridge 是普通对象(属性可配置)。影响面
命中
loginMethods与workbuddy-global分支的方法全部不可用:startLogin,以及登录弹窗的pollLogin/openLogin/cancelLoginworkbuddy-global的refreshQuotas、switchAccount、capture等(走workbuddyScope)与「仅国内版」拦截提示修复
不再用 Proxy 拦截,而是把 bridge 的方法表拷贝成普通对象(
Object.getOwnPropertyNames+ 描述符),再在副本上覆盖按地区改写的方法;对外行为、缓存与workbuddyScope转发逻辑保持不变。preload 与主进程无需改动。验证
tests/providers.test.mjs(6 项):用与 contextBridge 相同形状(不可写 + 不可配置)的对象作 target,覆盖登录方法转发 provider、国际版workbuddyScope路由、仅国内版方法拦截、未改写方法保持原引用、bridge 替换后缓存失效。修复前 6 项全部因同一 TypeError 失败,修复后全部通过。npm test:206 项,204 通过,0 失败,2 跳过(原有)。npm run typecheck、npm run build通过。