fix(mcp): record node actions inside web frames

Closed
SA
3d ago
+138-20

What

Tapping an observed button in a web frame now records a browser.frameLocator(...).getByRole(...).tap() line. locate is unchanged.

Why

The tap reached the button, but the recorder looked for a replay locator in the outer document.

How it works

  1. packages/e2e/src/session-tools/test-lines.ts:407 scopes each locator probe to the observed frame path and prints the same path in the draft. A redacted selector produces no line. A positional frame selector gets a warning.

  2. packages/e2e/tests/integration/mcp-test-lines.test.ts:116 replays a generated line through two nested frames and checks that the button changed. The MCP guide and skill describe the frame scope.

  3. packages/e2e/tests/integration/mcp-step-attachment.test.ts:246 takes the line from the paused Chromium session’s draft, reopens the page, and replays that exact line via run_code. The frame button changes from “Frame button” to “Frame clicked”.

  4. For paused and stopped tests, test_lines tells the author which engine fixtures the recorded lines need. A draft that only uses screen gets no extra hint.

  5. The web reader keeps traversing shadow-scoped iframes by element handle but omits their incomplete selector chain. The recorder declines a line instead of probing the outer document.

Issue

Fixes #2345

Verified

Ran it locally: yes

node packages/e2e/repro-frame/repro.mjs from the reproduction, against both built CLIs on Chromium:

mainthis PR
Counter after node tap11
Recorded tap// tap: no test lineawait browser.frameLocator(...).getByRole("button", "Save").tap();

MCP tap output on main and this branch

pnpm check passed. Both open/closed shadow regression cases failed before the fix and pass after it: the observed button changes, its light-DOM twin does not, and no tap line is drafted. The wider web run had 493 pass, 1 skip and 1 failure in the unmodified host-libraries ldd timeout test (also failed with one worker). After merging main at aaf923188, the old assertion that attached run_code rejects browser failed locally, as in CI. With the replay check, all 68 tests across the three related suites passed. Before the attachment follow-up, the e2e unit suite passed (5,051 passed, 2 skipped) and the web testbed passed (640 passed, 1 skipped). The image above shows the first fix; the final line also warns when the frame selector relies on position.

Checklist

  • Patch changeset, MCP docs and skill updated.
  • No change to public SDK types or wire formats.

Summary by CodeRabbit

  • New Features
    • Actions on controls inside observed web frames now generate replayable test steps scoped to the correct frame, including nested frames.
    • Generated tests include guidance when a browser fixture is needed.
  • Bug Fixes
    • Actions inside iframes within shadow roots still run, but no replay step is generated when the frame cannot be reliably targeted.
    • Frame selectors containing redacted secrets are excluded from generated test steps.
  • Documentation
    • Updated MCP guidance to explain frame-scoped actions and replay behavior.