fix(extension): count in-flight requests when waiting for network idle

RA
2mo ago
+109-0

why

NetworkManager.waitForIdle only tracked requests that started after the waiter registered its observer. LifecycleWatcher creates the waiter after the load state, so requests that began during page load and were still pending were never counted, and waitUntil: "networkidle" resolved 500 ms after load with those requests in flight. Requests that started a moment later did block the wait, which made the result timing dependent.

what changed

  • waitForIdle in packages/extension/understudy/networkManager.ts seeds its tracked set from the requests already in flight that started at or after startTime and pass the filter.
  • Adds packages/extension/tests/network-manager-idle.test.ts: one test for the in-flight request, one that keeps ignoring requests older than the wait window.
  • Adds a patch changeset.

Behavior note: a request that stays pending for the whole navigation (for example a long-lived fetch) now holds networkidle until the timeout, as it already did when the request started after the waiter was created. WebSocket and EventSource requests stay ignored, and the loader-scoped filter is unchanged.

test plan

  • pnpm exec vitest run --root . packages/extension/tests/network-manager-idle.test.ts passes (2 tests).
  • With the networkManager.ts change reverted, the in-flight test fails (1 failed, 1 passed).
  • The rest of packages/extension unit tests pass (436 passed); the three extension-build.test.ts tests fail only because no built extension artifact exists in the checkout.
  • oxfmt and oxlint report no errors; tsc --noEmit is clean.

Summary by cubic

Makes waitUntil: "networkidle" wait for requests that were already in flight when the idle wait began instead of resolving 500 ms after the load event.

  • waitForIdle now seeds its tracked set from requests already in flight that started within the wait window and match the filter.
  • Adds tests covering an in-flight request that delays the wait and older requests that stay ignored.
  • Adds a patch changeset for the @browserbasehq/stagehand packages.

A request that stays pending for the entire navigation now holds the wait until the timeout, matching the existing behavior for requests started after the waiter registered. WebSocket and EventSource requests remain ignored.