feat: 新增 /emulate 端点支持设备/移动视口模拟#142
Open
fireshort wants to merge 1 commit into
Open
Conversation
CDP proxy 增加 POST /emulate(Emulation.setDeviceMetricsOverride + 触摸模拟 + UA 覆盖), ?reset=1 清除覆盖。用于移动端 UI 验证(触发 matchMedia 断点、touch 检测、移动 UA), 免去每次手写 CDP 脚本连 browser 端点。override 作用于目标 session,emulate 后其 /eval /screenshot /click 保持该视口,reset 或 /close 即还原;纯新增路由,不影响现有端点。
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.
背景
用 web-access 验证移动端 UI时,CDP proxy 没有视口模拟能力:
/screenshot截的是当前窗口尺寸,靠matchMedia('(max-width: 768px)')触发的 mobile-only 样式在桌面窗口下根本测不到。目前只能绕过 proxy、自己连ws://…/devtools/browser+Target.attachToTarget+Emulation.setDeviceMetricsOverride手写一段 CDP 脚本,每次移动端验证都要重写。改动
CDP proxy 新增一个端点(纯增量路由,不碰任何现有端点):
字段均可选,默认
390x844 / dsf 2 / mobile true。移动端验证从「手写 30 行 CDP 脚本」变成一行
curl,之后该 tab 的/eval、/click、/screenshot都自动在移动视口下进行。行为与边界
reset或/close(关闭 tab 时 session 连 override 一并销毁)。建议只对自建临时 tab 使用。/emulate时行为零变化;proxy 原本没有任何Emulation.*调用,无冲突。测试
端到端验证(带
width=device-width的页面,等价真实 SSR 站点):innerWidthmatchMedia('(max-width: 768px)')screen.widthdevicePixelRatioreset=1后 innerWidth / dprnode --check通过。