[fix]: missing network events during iframe attachment

Merged
SE
10d ago
+1022-46

why

  • network events can begin in iframes before stagehand has a chance to install tracking. this means events get missed.

what changed

  • this PR queues tracker installation & Network.enable before the iframe is resumed
  • events that arrive before we know what page owns them (we call them pending network captures) are buffered & then transferred to their owning page in order
  • if attachment fails or the iframe closes, we dispose all pending captures

test plan

  • added unit tests for buffering, ownership transfer, ordering, & cleanup
  • added a real browser regression tests that cover immediate & later requests in same-process and cross-process iframes

Summary by cubic

Fixes network tracking missing requests made immediately by newly attached iframes.

Previously, Stagehand only started capturing network events after it identified which page owned the iframe, so requests fired right after attachment were lost. Now, capture is installed before the iframe resumes, and events that arrive before ownership is known are buffered and transferred to the owning page's network manager in arrival order.

  • Events retain their original arrival timestamps through the transfer.
  • Buffered events are discarded when attachment fails, the iframe detaches or closes, or the frame tree query fails.