feat(emulate): add mobile device emulation via CDP Emulation domain - #60
Merged
Conversation
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.
- 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
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.
Motivation
Agents driving real user browsers had no way to debug mobile page behaviour: the codebase made no use of the CDP Emulation domain at all — no viewport metrics override, no UA spoofing, no touch emulation. (Window sizing from #52 only resizes the real window; pages still see a desktop environment.)
What changes
New
bsk emulatecommand +tool.emulateend-to-end:Emulation.setDeviceMetricsOverride(width/height/deviceScaleFactor/mobile) — changes what the page sees (innerWidth, media queries, meta-viewport handling), unlike window resizing.Emulation.setUserAgentOverride, with optional accept-language and UA client-hints metadata (protocol-level).Emulation.setTouchEmulationEnabled+ maxTouchPoints, soontouchstart/ pointer media queries behave like a touch device.Explicitly out of scope (possible v2): real touch event streams (
Input.dispatchTouchEvent), network throttling, geolocation.Implementation
bsk-protocol:tool.emulatemethod (classified BrowserMutation),EmulateParams/EmulateOverrides/EmulateResulttypes + regenerated JSON schemas.emulatesubcommand (presets, validation, JSON/human output), daemon forwardsToolEmulateto the extension.ChromiumCdpEmulation wrappers, newtools/emulate.tshandler (off clears; otherwise viewport → UA → touch applied in order), dispatcher registration, transport types mirrored.SKILL.mdcopies gain a concise "Device emulation" section (presets,--off, per-tab scope).Tests
cli_parseintegration tests, 22 extension vitest cases for the handler.cargo fmt --all --check,clippy -p bsk-protocol -p bsk --all-targets -D warnings: clean.cargo test -p bsk-protocol: 113 passed.cargo test -p bsk --lib: 207 passed;sync_continues_on_partial_errorfails identically on cleanmainin this environment (pre-existing, env-dependent).pnpm lint,tsc --noEmit,wxt build,vom:testall clean; vitest +22 new tests green (41 pre-existingReact.actfailures in tsx files also fail identically on cleanmain).