Skip to content

The fastest browser for AI agents to run browser automation, built for sharing your logged-in browser state with your AI agents, like Codex or Claude Code, without disturbing you. Zero cost, zero config.

fix(ego-browser): only stop a navigation whose Page.navigate was dispatched

Zhuowei Wang866b5e8a0a35
diff --git a/package/ego-browser/src/driver/page-waits.ts b/package/ego-browser/src/driver/page-waits.ts
index 6b2709f..af3a9e2 100644
--- a/package/ego-browser/src/driver/page-waits.ts
+++ b/package/ego-browser/src/driver/page-waits.ts
@@ -484,6 +484,14 @@ export async function navigateInPage(
navigationTimeRemaining(services, deadline, timeoutMs, waitUntil),
),
);
+ // The budget check can throw at the deadline; only a request that was
+ // actually dispatched may be stopped later.
+ const navigateBudgetMs = navigationTimeRemaining(
+ services,
+ deadline,
+ timeoutMs,
+ waitUntil,
+ );
navigateSent = true;
const response = await services.cdp(
"Page.navigate",
@@ -492,7 +500,7 @@ export async function navigateInPage(
...(referer === undefined ? {} : { referrer: referer }),
},
sessionId,
- navigationTimeRemaining(services, deadline, timeoutMs, waitUntil),
+ navigateBudgetMs,
);
navigation = response?.result || response || {};
if (navigation.errorText) {
diff --git a/package/ego-browser/src/page-model.test.mjs b/package/ego-browser/src/page-model.test.mjs
index b066178..e47007c 100644
--- a/package/ego-browser/src/page-model.test.mjs
+++ b/package/ego-browser/src/page-model.test.mjs
@@ -2355,6 +2355,52 @@ test("Page.goto reports a navigation that commits while it is being stopped", as
});
});
+test("Page.goto does not stop anything when its budget ends before Page.navigate", async () => {
+ await withFixture(async (fixture) => {
+ const baseCdp = fixture.services.cdp;
+ let nowMs = 0;
+ let stops = 0;
+ let navigates = 0;
+ let armed = false;
+ const task = taskForRound(fixture, "round-a", {
+ async cdp(method, params, sessionId, timeoutMs) {
+ if (method === "Page.getFrameTree" && armed) {
+ // The pre-navigation probe is the last thing the budget covers.
+ nowMs += timeoutMs;
+ throw new CdpRequestTimeoutError(method, timeoutMs, sessionId);
+ }
+ if (method === "Page.navigate" && armed) navigates += 1;
+ if (method === "Page.stopLoading") stops += 1;
+ return baseCdp(method, params, sessionId, timeoutMs);
+ },
+ now: () => nowMs,
+ async sleep(ms) {
+ nowMs += ms;
+ },
+ });
+ const page = await openTestPage(task, "https://example.test/first");
+ nowMs = 0;
+ armed = true;
+
+ await assert.rejects(
+ () =>
+ page.goto("https://example.test/never-sent", {
+ timeout: 100,
+ waitUntil: "load",
+ }),
+ (error) => {
+ assert.equal(error.code, "EGO_NAVIGATION_TIMEOUT");
+ assert.equal(error.committed, false);
+ assert.equal(error.stopped, false);
+ assert.doesNotMatch(error.message, /pending|stopped|hung/);
+ return true;
+ },
+ );
+ assert.equal(navigates, 0, "Page.navigate was never dispatched");
+ assert.equal(stops, 0, "nothing in flight belongs to this call");
+ });
+});
+
test("Page.goto timeout on a responsive Page does not stop anything", async () => {
await withFixture(async (fixture) => {
const baseCdp = fixture.services.cdp;