feat: add device orientation and motion sensor mocking tools

Add CDP-based sensor mocking tools for testing motion-sensitive web apps:

- browser_set_device_orientation: Override DeviceOrientationEvent values
  (compass heading, front-back tilt, left-right tilt)
- browser_clear_device_orientation: Clear orientation override
- browser_set_device_motion: Override accelerometer and gyroscope values
  (acceleration, acceleration with gravity, rotation rate)
- browser_clear_device_motion: Clear motion override

These tools use Chrome DevTools Protocol (Chromium only) to mock sensor
readings, enabling testing of AR/VR apps, compass apps, games, and
other motion-sensitive web applications.

Also updates test snapshots to include all new core tools added recently.
This commit is contained in:
Ryan Malloy 2026-01-13 01:18:06 -07:00
parent b0ded548cf
commit a7d10f71bd
4 changed files with 410 additions and 9 deletions

View file

@ -606,6 +606,22 @@ http.createServer(async (req, res) => {
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_clear_device_motion**
- Title: Clear device motion override
- Description: Remove the device motion override and stop sending simulated motion events.
- Parameters: None
- Read-only: **false**
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_clear_device_orientation**
- Title: Clear device orientation override
- Description: Remove the device orientation override and return to default sensor behavior.
- Parameters: None
- Read-only: **false**
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_clear_injections**
- Title: Clear Injections
- Description: Remove all custom code injections (keeps debug toolbar)
@ -1209,6 +1225,62 @@ Full API: See MODEL-COLLABORATION-API.md
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_set_device_motion**
- Title: Set device motion sensors
- Description: Override accelerometer and gyroscope sensor values. Affects the DeviceMotionEvent API.
**Acceleration** (m/s²): Linear acceleration excluding gravity
- x: left(-) to right(+)
- y: down(-) to up(+)
- z: backward(-) to forward(+)
**Acceleration Including Gravity** (m/s²): Total acceleration including gravity
- At rest: { x: 0, y: -9.8, z: 0 } (Earth's gravity pulling down)
**Rotation Rate** (deg/s): Angular velocity around each axis
- alpha: rotation around z-axis
- beta: rotation around x-axis
- gamma: rotation around y-axis
**Common scenarios:**
- Device at rest: acceleration={x:0,y:0,z:0}, accelerationIncludingGravity={x:0,y:-9.8,z:0}
- Shaking horizontally: acceleration={x:5,y:0,z:0}
- Free fall: accelerationIncludingGravity={x:0,y:0,z:0}
**Note:** Requires Chromium-based browser.
- Parameters:
- `acceleration` (object, optional): Linear acceleration excluding gravity
- `accelerationIncludingGravity` (object, optional): Total acceleration including gravity
- `rotationRate` (object, optional): Angular velocity around each axis
- `interval` (number, optional): Interval between samples in milliseconds (default: 16)
- Read-only: **false**
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_set_device_orientation**
- Title: Set device orientation
- Description: Override device orientation sensor values. Affects the DeviceOrientationEvent API.
**Parameters:**
- **alpha** (0-360): Rotation around the z-axis (compass heading). 0 = North, 90 = East
- **beta** (-180 to 180): Front-to-back tilt. Positive = tilted backward
- **gamma** (-90 to 90): Left-to-right tilt. Positive = tilted right
**Common orientations:**
- Flat on table: alpha=any, beta=0, gamma=0
- Portrait upright: alpha=any, beta=90, gamma=0
- Landscape left: alpha=any, beta=0, gamma=90
- Tilted 45° forward: alpha=any, beta=-45, gamma=0
**Note:** Requires Chromium-based browser. This overrides the DeviceOrientationEvent.
- Parameters:
- `alpha` (number): Compass heading (0-360 degrees). 0=North, 90=East, 180=South, 270=West
- `beta` (number): Front-to-back tilt (-180 to 180 degrees). Positive=tilted backward
- `gamma` (number): Left-to-right tilt (-90 to 90 degrees). Positive=tilted right
- Read-only: **false**
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_set_geolocation**
- Title: Set geolocation at runtime
- Description: Set the browser's geolocation at runtime without restarting. Automatically grants geolocation permission.