ensureSimulatorBrowser
Ensure the simulator browser tab is attached to the session: open one if missing and confirm the WebSocket connection. Use before camera or photo flows to prevent browser-not-attached errors.
Instructions
Ensure a connected simulator browser tab for the session — opens one if needed and confirms the browser's WebSocket actually attached before returning. The browser tab is the hardware surrogate's viewport: camera + inject tools require it (setSimVideo returns browser_not_attached without it; the capture_photo / describe_scene flows the assistant runtime drives fail). Idempotent — if a browser is already connected it's a no-op (returns alreadyOpen: true); it never opens a redundant tab (the hub would reject a second live browser with role_conflict). When to call: right after createSimulatorSession before any camera-driven flow; after a backend deploy (which severs every sim WebSocket — the tab does NOT auto-reconnect); whenever the tab was closed; or any time getSimulatorStatus / a camera tool reports the browser isn't attached. How it works: checks the AUTHORITATIVE in-memory hub liveness (the same signal setSimVideo/inject enforce, so this can't disagree with them — unlike getSimulatorStatus.connectedRoles.browser, which is persisted state that can lag a dead socket ~25-50s after an unclean drop); if no browser is attached, the MCP server opens the session URL in the developer's default browser ITSELF (cross-platform — no shell command for you to run), then polls until the tab's WebSocket attaches or timeoutMs elapses. Headless / remote agents: pass autoOpen: false to get an immediate presence snapshot + the sessionUrl with NO spawn and NO wait — surface the URL to the developer to open on a machine with a display, then re-run with autoOpen:true to confirm. Returns { alreadyOpen, opened, browserConnected, browserClientId, appConnected, sessionUrl, waitedMs }; errors with browser_not_connected (carrying sessionUrl) when an auto-open didn't attach in time. DON'T USE to check whether the device APP is attached or hardware is ready — this ensures the BROWSER viewer only; use getSimulatorStatus for app/hardware state.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| autoOpen | No | When true (default): if no browser is connected the MCP server opens the session URL in the developer's default browser and polls until it attaches. When false: returns an immediate presence snapshot + sessionUrl with no spawn and no wait — for headless/remote agents that surface the URL to the developer themselves. | |
| sessionId | Yes | ||
| timeoutMs | No | Max ms to wait for the browser tab's WebSocket to attach after auto-opening. Default 20000. Clamped to [5000, 60000]. Bump it for a cold-started browser or a slow machine. Ignored when autoOpen:false. |