Repository navigation
Conversation
新版 Flow 前端(boq_labs-ai-sandbox-frontend_20261105.10_p0 起)不再调用
grecaptcha.enterprise.execute.bind(),同时启用了 Trusted Types CSP,导致
有头浏览器打码(captcha_method=browser)在取码阶段持续失败,最终报
"Failed to obtain reCAPTCHA token"。
具体改动:
- 取码脚本新增直接执行 enterprise.execute(siteKey, {action}) 的路径。
捕获闭包失败时不再渲染到 document.documentElement(该节点必然非空,
会抛 "reCAPTCHA placeholder element must be empty"),改为渲染到
新建的空容器兜底。
- 就绪检测改用 page.evaluate 轮询,替换 page.wait_for_function,避免
Trusted Types 下字符串 eval 抛
"violates Trusted Type assignment requirements"。
- 脚本注入改用 trustedTypes.createPolicy(...).createScriptURL(...),
不再使用在 Trusted Types 下必然失败的 add_script_tag。
- 修复 page.evaluate 传入多个位置参数导致的 TypeError,此前页面内
注入兜底路径从未真正执行。
- 同步修复自定义打码(分数测试)路径,并补充“新版前端不 bind”场景的
回归测试。
terry-xu-2077
pushed a commit
to terry-xu-2077/flow2api
that referenced
this pull request
Nov 11, 2026
…ect execute before waiting for bind hook Takes the PR's Trusted Types handling and structured errors, but reorders the execute strategy: direct enterprise.execute.call first, fresh-container render second, bind-hook capture (with a 10s wait) only as a last resort. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
问题现象
captcha_method = browser(有头浏览器打码)时,图片/视频生成固定在 38% 取码阶段失败:日志中反复出现:
同一账号/环境在 11/6 之前可以成功,11/8 起持续失败。
根因
Google Flow 前端在 11 月上旬灰度到新版本(响应 URL 的
bl参数由boq_labs-ai-sandbox-frontend_20261028.00_p0变为boq_labs-ai-sandbox-frontend_20261105.10_p0),同时命中旧代码的三个假设:取码闭包捕获失效
旧逻辑依赖页面调用
grecaptcha.enterprise.execute.bind(...),再由TRUSTED_RECAPTCHA_HOOK_SOURCE把绑定后的函数存入window.__flow2apiTrustedRecaptchaExecute。新前端不再bind,因此captured = false。兜底渲染必然报错
捕获不到闭包时,旧代码执行
enterprise.render(document.documentElement, ...)。documentElement永远有子节点,reCAPTCHA 会直接抛reCAPTCHA placeholder element must be empty,即日志中的报错。Trusted Types CSP 使两条注入兜底全部失效
page.wait_for_function("字符串表达式")触发页面内字符串 eval,被Trusted Types 拒绝,就绪检测永远失败;
page.add_script_tag(...)因TrustedScriptURL要求失败;page.evaluate(js, arg1, arg2)的多位置参数误用(Playwright Python 只接受一个 arg),实际从未执行成功。
验证
用真实账号 Cookie + 代理在本地 Playwright 中复现并确认:
应用本 PR 后,同一页面、同一 Cookie 下取码脚本返回:
{ "ok": true, "debug": { "captured": false, "executeType": "function", "renderType": "function" }, "token_len": 2660 }改动内容
src/services/recaptcha_runtime.py取码改为三级策略,逐级降级并在失败时返回每级的真实错误:
execute闭包(兼容旧前端,保留原有extension_hijack_detected动作保护逻辑);grecaptcha.enterprise.execute.call(enterprise, siteKey, {action})——企业版 v3 官方用法,无需 render,新前端实测可用;
documentElement),再按 widget id 执行。
src/services/browser_captcha.pypage.evaluate轮询替换page.wait_for_function,绕开 Trusted Types对字符串 eval 的限制;
trustedTypes.createPolicy(...).createScriptURL(...),替换在 Trusted Types 下必然失败的
add_script_tag;page.evaluate多位置参数导致的TypeError;tests/test_recaptcha_runtime.py新增回归测试:hook 未能捕获闭包时,必须走直接
execute路径,并校验this绑定、site key 与 action 未被改写。测试
另外
tests/test_browser_captcha_personal.py全部通过(recaptcha_runtime同时被 personal 模式复用)。
兼容性
execute(siteKey);captcha_method为personal时共用同一份取码脚本,同样受益;