Files
BrowserSkill/crates/bsk-protocol/schema/tool_emulate_params.json
T
BB-fat 0f264c5df1 feat(emulate): add mobile device emulation via CDP Emulation domain (#60)
* feat(emulate): add mobile device emulation via CDP Emulation domain

Add `bsk emulate` so agents can debug mobile page behaviour by
emulating a device environment on a session tab:

- Viewport metrics (Emulation.setDeviceMetricsOverride), User-Agent
  (Emulation.setUserAgentOverride, optional accept-language and UA
  client-hints metadata), and touch (Emulation.setTouchEmulationEnabled
  with maxTouchPoints).
- Seven CLI-side device presets (iphone-14, iphone-14-pro-max,
  iphone-se, pixel-7, galaxy-s23, ipad-mini, galaxy-tab-s8) via
  --device; manual flags (--width/--height/--dpr/--mobile/--ua/
  --accept-language/--touch/--max-touch-points) work standalone or
  override individual preset fields.
- `bsk emulate --off` clears every override (clearDeviceMetricsOverride
  + touch disabled + empty UA override) and restores the real
  environment.
- Overrides are per-tab (CDP per-target) and not inherited by new tabs;
  the result JSON carries a note reminding agents to re-apply.

Wire: new tool.emulate method end-to-end (bsk-protocol types + JSON
schemas + Method::ToolEmulate classified BrowserMutation, daemon
forwarding, CLI subcommand, extension tool handler + ChromiumCdp
Emulation wrappers, dispatcher registration), docs in both SKILL.md
copies, and unit tests on every layer.

* refine(emulate): merge per-tab state and align preset override semantics

- extension: remember the applied emulation state per tab and merge each new request onto it field by field before applying, so a later --width/--height no longer resets an earlier preset's dpr/mobile; --off clears the stored state along with the CDP overrides
- extension: cdp_failed errors now note that already-applied overrides were not rolled back and can be reset with --off
- cli: validate width/height pairing and metric requirements on the merged preset+flags result, so --device iphone-14 --width 500 keeps the preset height
- cli: add --no-mobile/--no-touch (conflicting with --mobile/--touch) to turn preset mobile/touch fields back off
- docs: describe the merge behaviour, --no-mobile/--no-touch and --off state clearing in both SKILL.md copies
2026-08-05 18:10:39 +08:00

189 lines
4.8 KiB
JSON

{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "EmulateParams",
"type": "object",
"required": [
"session_id"
],
"properties": {
"off": {
"description": "Clear every emulation override on the tab and restore its real environment. Mutually exclusive with `overrides`.",
"type": [
"boolean",
"null"
]
},
"overrides": {
"description": "Overrides to apply. Required unless `off` is set.",
"anyOf": [
{
"$ref": "#/definitions/EmulateOverrides"
},
{
"type": "null"
}
]
},
"session_id": {
"type": "string"
},
"tab_id": {
"description": "Target tab. Defaults to the Agent Window's active tab.",
"type": [
"integer",
"null"
],
"format": "int64"
}
},
"definitions": {
"EmulateOverrides": {
"description": "Concrete emulation overrides for one tab. Field presence drives the extension: only the overrides whose fields are set are touched, so a call may change just the UA, just the viewport, or any combination.",
"type": "object",
"properties": {
"accept_language": {
"description": "`Accept-Language` header override. Requires `user_agent`.",
"type": [
"string",
"null"
]
},
"device_scale_factor": {
"description": "Device scale factor (device pixel ratio). Only meaningful with `width`/`height`; the extension maps `None` to CDP's `0` (\"use the display's native factor\").",
"type": [
"number",
"null"
],
"format": "double"
},
"height": {
"description": "Viewport height in CSS pixels. Requires `width`.",
"type": [
"integer",
"null"
],
"format": "uint32",
"minimum": 0.0
},
"max_touch_points": {
"description": "Touch points reported while touch emulation is on (CDP defaults to 1 when omitted).",
"type": [
"integer",
"null"
],
"format": "uint32",
"minimum": 0.0
},
"mobile": {
"description": "Emulate a mobile viewport (meta-viewport handling, overlay scrollbars). Only meaningful with `width`/`height`.",
"type": [
"boolean",
"null"
]
},
"touch": {
"description": "Enable/disable touch emulation (`Emulation.setTouchEmulationEnabled`). When omitted while `max_touch_points` is set, touch is enabled.",
"type": [
"boolean",
"null"
]
},
"user_agent": {
"description": "UA string for `Emulation.setUserAgentOverride`.",
"type": [
"string",
"null"
]
},
"user_agent_metadata": {
"description": "UA client-hints metadata. Requires `user_agent`.",
"anyOf": [
{
"$ref": "#/definitions/UserAgentMetadata"
},
{
"type": "null"
}
]
},
"width": {
"description": "Viewport width in CSS pixels. Requires `height`.",
"type": [
"integer",
"null"
],
"format": "uint32",
"minimum": 0.0
}
}
},
"UserAgentBrandVersion": {
"description": "One entry of CDP `Emulation.UserAgentBrandVersion` (UA client hints).",
"type": "object",
"required": [
"brand",
"version"
],
"properties": {
"brand": {
"type": "string"
},
"version": {
"type": "string"
}
}
},
"UserAgentMetadata": {
"description": "Mirror of CDP `Emulation.UserAgentMetadata`; every field is optional and only sent when present.",
"type": "object",
"properties": {
"architecture": {
"type": [
"string",
"null"
]
},
"brands": {
"type": [
"array",
"null"
],
"items": {
"$ref": "#/definitions/UserAgentBrandVersion"
}
},
"full_version": {
"type": [
"string",
"null"
]
},
"mobile": {
"type": [
"boolean",
"null"
]
},
"model": {
"type": [
"string",
"null"
]
},
"platform": {
"type": [
"string",
"null"
]
},
"platform_version": {
"type": [
"string",
"null"
]
}
}
}
}
}