fix(extension): count in-flight requests when waiting for network idle
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
waitForIdleinpackages/extension/understudy/networkManager.tsseeds its tracked set from the requests already in flight that started at or afterstartTimeand 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.tspasses (2 tests).- With the
networkManager.tschange reverted, the in-flight test fails (1 failed, 1 passed). - The rest of
packages/extensionunit tests pass (436 passed); the threeextension-build.test.tstests fail only because no built extension artifact exists in the checkout. oxfmtandoxlintreport no errors;tsc --noEmitis 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.
waitForIdlenow 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/stagehandpackages.
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.