fix(chv-muse-round12): 移植 round-11 的 Page.aria_snapshot() 纠正到 CDP broker

Playwright 1.64.1 没有 page.accessibility(Puppeteer 的 API),
broker 的 snapshot 调它必走异常分支。改调 Page.aria_snapshot()
(字符串);guard 的 truncate_a11y 换成字符串版 truncate_aria
(179a86d 原样),detect_injection/detect_form_risk 加字符串
分支(dict 分支保留);两边 fake 与 P4 文档同步改。a11y-only
契约不变:不读原始 DOM、不走 JS eval。

测试:test_chv_muse_p2 + test_chv_muse_p4 114 OK;全量 2523 OK
(skipped=10)。
This commit is contained in:
host committed 2026-11-07 18:24:58 +00:00
1 parent 9da74c2a78
commit 114b444554
6 files changed
+209 -129

No files matched your search

+13 -6
View File
@@ -32,7 +32,7 @@ socket 说话,绝不直连浏览器、绝不见 CDP 端点。
DevTools 地址、原始 HTML。
Playwright 调用白名单:launch/goto/wait_for_load_state/title/
url/accessibility.snapshot/screenshot/close + 只读监听
url/aria_snapshot/screenshot/close + 只读监听
on(request/download)。evaluate/add_script_tag/add_init_script/
expose_function/set_content 等脚本注入面不在代码里出现,
测试用 AST 扫本文件钉住。
@@ -212,16 +212,23 @@ class CdpBroker:
try:
title = self._page.title()
url = self._page.url
tree = self._page.accessibility.snapshot()
# round-12 移植 round-11 的 179a86d 纠正:Playwright
# 没有 page.accessibility(Puppeteer 的 API),原生
# 快照是 Page.aria_snapshot()(字符串);a11y 字段仍
# 叫 a11y,值改为 ARIA 快照字符串(截断到 200 节点
# 行/64KB)。合入 round-12 时这处遗漏,仍调不存在的
# accessibility.snapshot(),真机上 snapshot 必走异常
# 分支返回错误。
aria = self._page.aria_snapshot()
except Exception as e:
return {"ok": False,
"error": self._guard.sanitize_error(e)}
tree, truncated = self._guard.truncate_a11y(tree or {})
flags = self._guard.detect_injection(tree)
self._form_risk = self._guard.detect_form_risk(tree)
aria, truncated = self._guard.truncate_aria(aria or "")
flags = self._guard.detect_injection(aria)
self._form_risk = self._guard.detect_form_risk(aria)
self._current_url = url
return {"ok": True, "title": title, "url": url,
"a11y": tree, "truncated": truncated,
"a11y": aria, "truncated": truncated,
"untrusted_input": True, "injection_flags": flags,
"form_risk": self._form_risk}