Reuse browser session setup across locator calls

AR
4d ago
+338-15

why

Repeated locator calls send Runtime.enable and DOM.enable to the same browser session even after setup succeeds. This addresses the repeated setup portion of #3239. #3326 covers logging overhead, and element-handle reuse is a separate part of the issue.

what changed

Internal locator operations share each session’s pending or successful setup. A failed request can be retried. Explicit enable and disable commands still reach Chrome and invalidate saved setup for their domain. Session teardown clears the saved state.

test plan

  • The focused transport tests count commands sent to the browser. Before the fix, 12 of 14 cases failed. All 14 pass with the fix, including retry, reset, concurrency, and independent caller timeouts.
  • Ran 23 local Chrome tests covering repeated fills and reads, navigation, iframes, and page closure.
  • The full just check stops on main’s existing agent-discoverability-metadata.md release entry. The release validator accepts this change’s entry. In the broader Python run, 1,093 tests passed, nine were skipped, and four were excluded after a transport test hung during cleanup.

Summary by cubic

Internal locator calls now reuse pending or successful DOM.enable and Runtime.enable setup within each browser session, avoiding repeated setup commands.

  • Failed setup can be retried; explicit enable and disable commands still reach Chrome and refresh the saved state.
  • Session teardown clears saved setup, and separate sessions keep independent state.
  • Tests cover retries, concurrency, timeouts, navigation, and multiple pages.