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): stop a navigation that has not committed by the goto timeout

Zhuowei Wang13ed2d49618d
diff --git a/package/ego-browser/scripts/real-browser-e2e/cases/page-pending-navigation.mjs b/package/ego-browser/scripts/real-browser-e2e/cases/page-pending-navigation.mjs
index f32ceed..954cfcf 100644
--- a/package/ego-browser/scripts/real-browser-e2e/cases/page-pending-navigation.mjs
+++ b/package/ego-browser/scripts/real-browser-e2e/cases/page-pending-navigation.mjs
@@ -12,6 +12,8 @@ export function pagePendingNavigationCase() {
);
const heldUrl = baseUrl + "/hold-page?ms=120000";
+ // goto bounds its own wait and stops the navigation it could not commit,
+ // so the Page keeps answering on its previous document.
const gotoStartedAt = Date.now();
let gotoError;
try {
@@ -28,7 +30,40 @@ export function pagePendingNavigationCase() {
Date.now() - gotoStartedAt < 4_000,
"goto returns close to its own timeout: " + (Date.now() - gotoStartedAt)
);
+ assertEqual(gotoError?.committed, false, "the held navigation did not commit");
+ assertEqual(gotoError?.stopped, true, "goto stopped the pending navigation");
+ assertIncludes(
+ gotoError?.message,
+ "had not committed and was stopped",
+ "the goto error says the navigation was stopped"
+ );
+ assertIncludes(
+ gotoError?.message,
+ "page.goto(url, { timeout })",
+ "the goto error tells the agent how to retry"
+ );
+ const afterGotoStartedAt = Date.now();
+ const afterGoto = await page.snapshot();
+ assert(
+ Date.now() - afterGotoStartedAt < 5_000,
+ "snapshot answers promptly after goto stopped the navigation: " +
+ (Date.now() - afterGotoStartedAt)
+ );
+ assertIncludes(
+ afterGoto,
+ "Navigation target",
+ "the Page still shows the last committed document after goto gave up"
+ );
+
+ // A navigation that goto did not start (a link click, a script, raw CDP)
+ // can still be left pending; public calls then stay inside one bounded
+ // wait and the error names the Page and what to do. Chromium answers
+ // Page.navigate only once the response arrives, so the raw call is given
+ // up on while the navigation stays pending.
+ await page
+ .cdp("Page.navigate", { url: heldUrl + "&raw=1" }, { timeout: 500 })
+ .catch(() => {});
const snapshotStartedAt = Date.now();
let snapshotError;
try {
@@ -64,6 +99,8 @@ export function pagePendingNavigationCase() {
snapshotElapsed
);
+ // goto on such a Page replaces the pending navigation with its own, times
+ // out within its budget, and leaves the Page usable again.
const secondGotoStartedAt = Date.now();
let secondGotoError;
try {
@@ -81,13 +118,16 @@ export function pagePendingNavigationCase() {
"goto on an unresponsive Page counts session setup against its timeout: " +
(Date.now() - secondGotoStartedAt)
);
-
- await page.cdp("Page.stopLoading");
+ assertEqual(
+ secondGotoError?.stopped,
+ true,
+ "goto on an unresponsive Page stops the navigation it started"
+ );
const recoveredStartedAt = Date.now();
const recovered = await page.snapshot();
assert(
Date.now() - recoveredStartedAt < 5_000,
- "snapshot answers promptly once the pending navigation stops: " +
+ "snapshot answers promptly once goto stopped the pending navigation: " +
(Date.now() - recoveredStartedAt)
);
assertIncludes(
@@ -97,9 +137,9 @@ export function pagePendingNavigationCase() {
);
// Leave a pending navigation behind for the fresh-process case.
- try {
- await page.goto(heldUrl + "&fresh=1", { timeout: 1_000 });
- } catch {}
+ await page
+ .cdp("Page.navigate", { url: heldUrl + "&fresh=1" }, { timeout: 500 })
+ .catch(() => {});
await writeFile(
join(tempDir, "pending-navigation-state.json"),
JSON.stringify({ label: page.label })
diff --git a/package/ego-browser/skill-body/SKILL.md b/package/ego-browser/skill-body/SKILL.md
index f936c3f..f8b6be7 100644
--- a/package/ego-browser/skill-body/SKILL.md
+++ b/package/ego-browser/skill-body/SKILL.md
@@ -220,8 +220,11 @@ ego-browser provides the following Page API:
or Node.js modules from the surrounding script. Define browser-side helpers
inside the callback or pass one JSON-serializable value as its second argument.
-A Page whose navigation has not committed fails with `EGO_PAGE_UNRESPONSIVE`;
-the error says how to recover (`page.cdp("Page.stopLoading")`, a new Page).
+`goto()` and `reload()` stop a navigation that has not committed by their
+timeout, so the Page stays usable on its previous document; retry with a longer
+timeout. A Page whose navigation is pending for any other reason fails with
+`EGO_PAGE_UNRESPONSIVE`; the error says how to recover
+(`page.cdp("Page.stopLoading")`, a new Page).
Work efficiently:
diff --git a/package/ego-browser/src/driver/page-waits.ts b/package/ego-browser/src/driver/page-waits.ts
index 605fc1d..7f1f20e 100644
--- a/package/ego-browser/src/driver/page-waits.ts
+++ b/package/ego-browser/src/driver/page-waits.ts
@@ -89,6 +89,11 @@ export type PageWaitForURLHooks = {
export class PageNavigationTimeoutError extends Error {
readonly code = "EGO_NAVIGATION_TIMEOUT";
readonly committed: boolean;
+ /**
+ * The navigation had started but not committed by the deadline, and the
+ * harness stopped it so the Page keeps answering on its previous document.
+ */
+ readonly stopped: boolean;
readonly url?: string;
readonly readyState?: string;
readonly waitUntil: PageGotoWaitUntil;
@@ -98,6 +103,7 @@ export class PageNavigationTimeoutError extends Error {
message: string,
details: {
committed: boolean;
+ stopped?: boolean;
url?: string;
readyState?: string;
waitUntil: PageGotoWaitUntil;
@@ -107,6 +113,7 @@ export class PageNavigationTimeoutError extends Error {
super(message);
this.name = "PageNavigationTimeoutError";
this.committed = details.committed;
+ this.stopped = details.stopped === true;
this.url = details.url;
this.readyState = details.readyState;
this.waitUntil = details.waitUntil;
@@ -114,6 +121,17 @@ export class PageNavigationTimeoutError extends Error {
}
}
+// Page.stopLoading is answered by the browser process, so a pending
+// navigation cannot stall it; the frame-tree probe afterwards confirms the
+// renderer answers again. Both stay short: they run after the caller's
+// deadline has already passed.
+const STOP_PENDING_NAVIGATION_TIMEOUT_MS = 1_000;
+// A responsive Page answers Page.getFrameTree within milliseconds. The probe
+// before Page.navigate only records the current document; the probe at the
+// deadline decides whether the navigation is still pending.
+const PREVIOUS_DOCUMENT_PROBE_TIMEOUT_MS = 500;
+const NAVIGATION_DEADLINE_PROBE_TIMEOUT_MS = 250;
+
const VISIBILITY_FUNCTION =
"function(){if(typeof this.checkVisibility==='function')return this.checkVisibility({checkOpacity:true,checkVisibilityCSS:true});const s=getComputedStyle(this);const r=this.getBoundingClientRect();return s.display!=='none'&&s.visibility!=='hidden'&&s.opacity!=='0'&&r.width>0&&r.height>0;}";
@@ -435,6 +453,8 @@ export async function navigateInPage(
const { timeoutMs, waitUntil, referer } = options;
const deadline = options.deadline ?? services.now() + timeoutMs;
let committed = false;
+ let navigateSent = false;
+ let previousFrame: MainFrame = {};
let navigation: {
frameId?: string;
loaderId?: string;
@@ -450,6 +470,19 @@ export async function navigateInPage(
navigationTimeRemaining(services, deadline, timeoutMs, waitUntil),
);
}
+ // Chromium answers Page.navigate only once the navigation is ready to
+ // commit or has failed, so a held response leaves this call without a
+ // loaderId. The document in place before the request is the reference
+ // the deadline probe compares against instead.
+ previousFrame = await mainFrameIfResponsive(
+ services,
+ sessionId,
+ Math.min(
+ PREVIOUS_DOCUMENT_PROBE_TIMEOUT_MS,
+ navigationTimeRemaining(services, deadline, timeoutMs, waitUntil),
+ ),
+ );
+ navigateSent = true;
const response = await services.cdp(
"Page.navigate",
{
@@ -488,26 +521,133 @@ export async function navigateInPage(
});
} catch (error) {
if (services.now() >= deadline || isLoadStateTimeout(error)) {
- if (!committed && navigation.loaderId) {
- committed = await navigationMatchesCurrentFrame(
+ let probe: NavigationProbe = committed ? "committed" : "not-committed";
+ if (!committed && navigateSent) {
+ probe = await probeNavigation(
services,
sessionId,
navigation,
- 250,
+ previousFrame,
);
+ committed = probe === "committed";
}
const state = committed
? await currentDocumentState(services, sessionId)
: {};
+ // Chromium suspends every renderer-bound command while a main-frame
+ // navigation has started but not committed, so leaving it pending would
+ // hand back a Page that stalls each later call for a full transport
+ // timeout. The caller asked for a bounded wait: stop the navigation and
+ // leave the Page usable on its previous document.
+ const pending = probe === "unresponsive";
+ const stopped = pending
+ ? await stopPendingNavigation(services, sessionId)
+ : false;
throw navigationTimeout(timeoutMs, waitUntil, {
committed,
...state,
+ ...(pending ? { pending: { url, stopped } } : {}),
});
}
throw error;
}
}
+type NavigationProbe = "committed" | "not-committed" | "unresponsive";
+
+/**
+ * One short frame-tree probe at a navigation deadline. A Page that answers
+ * has no main-frame navigation pending: either the requested document is in
+ * place (matched by the loaderId Page.navigate reported, or by any change
+ * from the document that was there before) or nothing replaced the previous
+ * one. A Page that does not answer still has the navigation pending.
+ */
+async function probeNavigation(
+ services: PageWaitServices,
+ sessionId: string,
+ navigation: { frameId?: string; loaderId?: string },
+ previousFrame: MainFrame,
+): Promise<NavigationProbe> {
+ let frame: MainFrame;
+ try {
+ frame = await mainFrame(
+ services,
+ sessionId,
+ NAVIGATION_DEADLINE_PROBE_TIMEOUT_MS,
+ );
+ } catch (error) {
+ if (isCdpTimeout(error, "Page.getFrameTree")) return "unresponsive";
+ // Any other failure is not evidence of a pending navigation.
+ return "not-committed";
+ }
+ if (navigation.loaderId) {
+ return frame.loaderId === navigation.loaderId &&
+ (!navigation.frameId || frame.id === navigation.frameId)
+ ? "committed"
+ : "not-committed";
+ }
+ return previousFrame.loaderId &&
+ frame.loaderId &&
+ frame.loaderId !== previousFrame.loaderId
+ ? "committed"
+ : "not-committed";
+}
+
+/** The main frame, or an empty record when the Page does not answer in time. */
+async function mainFrameIfResponsive(
+ services: PageWaitServices,
+ sessionId: string,
+ timeoutMs: number,
+): Promise<MainFrame> {
+ try {
+ return await mainFrame(services, sessionId, timeoutMs);
+ } catch {
+ return {};
+ }
+}
+
+/**
+ * Stop a navigation that has not committed and confirm the Page answers
+ * renderer commands again. Best-effort: a hung renderer answers neither.
+ */
+async function stopPendingNavigation(
+ services: PageWaitServices,
+ sessionId: string,
+): Promise<boolean> {
+ try {
+ await services.cdp(
+ "Page.stopLoading",
+ {},
+ sessionId,
+ STOP_PENDING_NAVIGATION_TIMEOUT_MS,
+ );
+ await services.cdp(
+ "Page.getFrameTree",
+ {},
+ sessionId,
+ STOP_PENDING_NAVIGATION_TIMEOUT_MS,
+ );
+ return true;
+ } catch {
+ return false;
+ }
+}
+
+/**
+ * The sentence a timeout error adds when the navigation it waited for is
+ * still pending or was stopped, so the agent knows which document the Page
+ * shows and what to do next.
+ */
+function pendingNavigationNote(
+ what: string,
+ stopped: boolean,
+ retry: string,
+): string {
+ return stopped
+ ? `; ${what} had not committed and was stopped, so the Page still shows its previous document. Retry ${retry} with a longer timeout, or continue on a new Page from task.newPage().`
+ : `; ${what} has not committed and is still pending, so the Page answers no renderer command until it commits. Stop it with page.cdp("Page.stopLoading") or continue on a new Page from task.newPage().`;
+}
+
/** Reload one Page and wait for the selected state of the new document. */
export async function reloadInPage(
services: PageWaitServices,
@@ -516,8 +656,11 @@ export async function reloadInPage(
): Promise<void> {
const { timeoutMs, waitUntil } = options;
const deadline = options.deadline ?? services.now() + timeoutMs;
+ let reloadSent = false;
+ let committed = false;
+ let previousFrame: MainFrame = {};
try {
- const previousFrame = await mainFrame(
+ previousFrame = await mainFrame(
services,
sessionId,
reloadTimeRemaining(services, deadline, timeoutMs, waitUntil),
@@ -536,6 +679,7 @@ export async function reloadInPage(
sessionId,
reloadTimeRemaining(services, deadline, timeoutMs, waitUntil),
);
+ reloadSent = true;
await waitForReloadCommit(
services,
sessionId,
@@ -544,13 +688,34 @@ export async function reloadInPage(
timeoutMs,
waitUntil,
);
+ committed = true;
if (waitUntil === "commit") return;
await waitForLoadStateInPage(services, sessionId, waitUntil, {
timeout: reloadTimeRemaining(services, deadline, timeoutMs, waitUntil),
});
} catch (error) {
if (services.now() >= deadline || isLoadStateTimeout(error)) {
- throw reloadTimeout(timeoutMs, waitUntil);
+ // Same as page.goto: a reload that has not committed stalls every later
+ // call on this Page, so stop it before reporting the timeout.
+ const pending =
+ !committed &&
+ reloadSent &&
+ (await probeNavigation(services, sessionId, {}, previousFrame)) ===
+ "unresponsive";
+ const stopped = pending
+ ? await stopPendingNavigation(services, sessionId)
+ : false;
+ throw reloadTimeout(
+ timeoutMs,
+ waitUntil,
+ pending
+ ? pendingNavigationNote(
+ "the reload",
+ stopped,
+ "page.reload({ timeout })",
+ )
+ : "",
+ );
}
throw error;
}
@@ -621,9 +786,13 @@ function reloadTimeRemaining(
return remaining;
}
-function reloadTimeout(timeoutMs: number, waitUntil: PageGotoWaitUntil): Error {
+function reloadTimeout(
+ timeoutMs: number,
+ waitUntil: PageGotoWaitUntil,
+ note = "",
+): Error {
return new Error(
- `page.reload timed out after ${timeoutMs}ms waiting for ${waitUntil}`,
+ `page.reload timed out after ${timeoutMs}ms waiting for ${waitUntil}${note}`,
);
}
@@ -672,32 +841,6 @@ async function waitForNavigationCommit(
throw navigationTimeout(timeoutMs, waitUntil);
}
-async function navigationMatchesCurrentFrame(
- services: PageWaitServices,
- sessionId: string,
- navigation: { frameId?: string; loaderId?: string },
- timeoutMs: number,
-): Promise<boolean> {
- try {
- const response = await services.cdp(
- "Page.getFrameTree",
- {},
- sessionId,
- timeoutMs,
- );
- const frame =
- response?.result?.frameTree?.frame || response?.frameTree?.frame;
- return (
- Boolean(navigation.loaderId) &&
- frame?.loaderId === navigation.loaderId &&
- (!navigation.frameId || frame?.id === navigation.frameId)
- );
- } catch {
- // This is a best-effort timeout diagnostic, not a second navigation path.
- return false;
- }
-}
-
function navigationTimeRemaining(
services: PageWaitServices,
deadline: number,
@@ -712,17 +855,30 @@ function navigationTimeRemaining(
function navigationTimeout(
timeoutMs: number,
waitUntil: PageGotoWaitUntil,
- details: { committed?: boolean; url?: string; readyState?: string } = {},
+ details: {
+ committed?: boolean;
+ url?: string;
+ readyState?: string;
+ pending?: { url: string; stopped: boolean };
+ } = {},
): PageNavigationTimeoutError {
const committed = details.committed === true;
const nextStep = navigationTimeoutNextStep(waitUntil);
- const state = committed
- ? `; navigation committed${details.url ? ` at ${JSON.stringify(details.url)}` : ""}${details.readyState ? ` with document.readyState=${JSON.stringify(details.readyState)}` : ""}. ${nextStep}`
- : "";
+ let state = "";
+ if (committed) {
+ state = `; navigation committed${details.url ? ` at ${JSON.stringify(details.url)}` : ""}${details.readyState ? ` with document.readyState=${JSON.stringify(details.readyState)}` : ""}. ${nextStep}`;
+ } else if (details.pending) {
+ state = pendingNavigationNote(
+ `the navigation to ${JSON.stringify(details.pending.url)}`,
+ details.pending.stopped,
+ "page.goto(url, { timeout })",
+ );
+ }
return new PageNavigationTimeoutError(
`page.goto timed out after ${timeoutMs}ms waiting for ${waitUntil}${state}`,
{
committed,
+ stopped: details.pending?.stopped === true,
url: details.url,
readyState: details.readyState,
waitUntil,
diff --git a/package/ego-browser/src/page-model.test.mjs b/package/ego-browser/src/page-model.test.mjs
index a3e6421..377a5e6 100644
--- a/package/ego-browser/src/page-model.test.mjs
+++ b/package/ego-browser/src/page-model.test.mjs
@@ -2052,7 +2052,11 @@ test("Page.goto commit waits for this navigation without waiting for the DOM", a
waitUntil: "commit",
});
- assert.equal(commitChecks, 2);
+ assert.equal(
+ commitChecks,
+ 3,
+ "one frame check records the previous document, two wait for the commit",
+ );
assert.equal(
fixture.calls
.slice(callsBeforeGoto)
@@ -2156,6 +2160,194 @@ test("Page.goto timeout reports when no new document committed", async () => {
});
});
+test("Page.goto stops a navigation that has not committed by its timeout", async () => {
+ await withFixture(async (fixture) => {
+ const baseCdp = fixture.services.cdp;
+ let nowMs = 0;
+ let held = false;
+ const stops = [];
+ let frameChecksAfterStop = 0;
+ const task = taskForRound(fixture, "round-a", {
+ async cdp(method, params, sessionId, timeoutMs) {
+ if (method === "Page.navigate") {
+ const response = await baseCdp(method, params, sessionId, timeoutMs);
+ if (params.url !== "https://example.test/held") return response;
+ // Chromium answers Page.navigate only once the response arrives.
+ held = true;
+ nowMs += timeoutMs;
+ throw new CdpRequestTimeoutError(method, timeoutMs, sessionId);
+ }
+ if (method === "Page.stopLoading") {
+ stops.push({ sessionId, timeoutMs });
+ held = false;
+ return {};
+ }
+ if (method === "Page.getFrameTree") {
+ if (held)
+ throw new CdpRequestTimeoutError(method, timeoutMs, sessionId);
+ if (stops.length > 0) frameChecksAfterStop += 1;
+ return {
+ result: {
+ frameTree: { frame: { id: "frame-1", loaderId: "loader-old" } },
+ },
+ };
+ }
+ return baseCdp(method, params, sessionId, timeoutMs);
+ },
+ now: () => nowMs,
+ async sleep(ms) {
+ nowMs += ms;
+ },
+ });
+ const page = await openTestPage(task, "https://example.test/first");
+ nowMs = 0;
+
+ await assert.rejects(
+ () =>
+ page.goto("https://example.test/held", {
+ timeout: 100,
+ waitUntil: "load",
+ }),
+ (error) => {
+ assert.equal(error.code, "EGO_NAVIGATION_TIMEOUT");
+ assert.equal(error.committed, false);
+ assert.equal(error.stopped, true);
+ assert.equal(error.url, undefined);
+ assert.match(
+ error.message,
+ /^page\.goto timed out after 100ms waiting for load; the navigation to "https:\/\/example\.test\/held" had not committed and was stopped, so the Page still shows its previous document\./,
+ );
+ assert.match(error.message, /Retry page\.goto\(url, \{ timeout \}\)/);
+ assert.match(error.message, /task\.newPage\(\)/);
+ return true;
+ },
+ );
+ assert.equal(stops.length, 1, "the pending navigation is stopped once");
+ assert.equal(typeof stops[0].sessionId, "string");
+ assert.equal(
+ stops[0].timeoutMs,
+ 1_000,
+ "stopping never waits a transport timeout",
+ );
+ assert.equal(
+ frameChecksAfterStop,
+ 1,
+ "the Page is confirmed responsive after the navigation stops",
+ );
+ });
+});
+
+test("Page.goto names a pending navigation it could not stop", async () => {
+ await withFixture(async (fixture) => {
+ const baseCdp = fixture.services.cdp;
+ let nowMs = 0;
+ let held = false;
+ const task = taskForRound(fixture, "round-a", {
+ async cdp(method, params, sessionId, timeoutMs) {
+ if (method === "Page.navigate") {
+ const response = await baseCdp(method, params, sessionId, timeoutMs);
+ if (params.url !== "https://example.test/held") return response;
+ held = true;
+ nowMs += timeoutMs;
+ throw new CdpRequestTimeoutError(method, timeoutMs, sessionId);
+ }
+ if (method === "Page.stopLoading") {
+ throw new CdpRequestTimeoutError(method, timeoutMs, sessionId);
+ }
+ if (method === "Page.getFrameTree") {
+ if (held)
+ throw new CdpRequestTimeoutError(method, timeoutMs, sessionId);
+ return {
+ result: {
+ frameTree: { frame: { id: "frame-1", loaderId: "loader-old" } },
+ },
+ };
+ }
+ return baseCdp(method, params, sessionId, timeoutMs);
+ },
+ now: () => nowMs,
+ async sleep(ms) {
+ nowMs += ms;
+ },
+ });
+ const page = await openTestPage(task, "https://example.test/first");
+ nowMs = 0;
+
+ await assert.rejects(
+ () =>
+ page.goto("https://example.test/held", {
+ timeout: 100,
+ waitUntil: "load",
+ }),
+ (error) => {
+ assert.equal(error.code, "EGO_NAVIGATION_TIMEOUT");
+ assert.equal(error.committed, false);
+ assert.equal(error.stopped, false);
+ assert.match(
+ error.message,
+ /the navigation to "https:\/\/example\.test\/held" has not committed and is still pending/,
+ );
+ assert.match(error.message, /page\.cdp\("Page\.stopLoading"\)/);
+ assert.doesNotMatch(error.message, /was stopped/);
+ return true;
+ },
+ );
+ });
+});
+
+test("Page.goto timeout on a responsive Page does not stop anything", async () => {
+ await withFixture(async (fixture) => {
+ const baseCdp = fixture.services.cdp;
+ let nowMs = 0;
+ let stops = 0;
+ const task = taskForRound(fixture, "round-a", {
+ async cdp(method, params, sessionId, timeoutMs) {
+ if (method === "Page.navigate") {
+ const response = await baseCdp(method, params, sessionId, timeoutMs);
+ if (params.url !== "https://example.test/answering") return response;
+ return {
+ result: { frameId: "frame-1", loaderId: "loader-new" },
+ };
+ }
+ if (method === "Page.stopLoading") {
+ stops += 1;
+ return {};
+ }
+ if (method === "Page.getFrameTree") {
+ return {
+ result: {
+ frameTree: { frame: { id: "frame-1", loaderId: "loader-old" } },
+ },
+ };
+ }
+ return baseCdp(method, params, sessionId, timeoutMs);
+ },
+ now: () => nowMs,
+ async sleep(ms) {
+ nowMs += ms;
+ },
+ });
+ const page = await openTestPage(task, "https://example.test/first");
+ nowMs = 0;
+
+ await assert.rejects(
+ () =>
+ page.goto("https://example.test/answering", {
+ 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/);
+ return true;
+ },
+ );
+ assert.equal(stops, 0, "a Page that answers has nothing to stop");
+ });
+});
+
test("Page.goto performs one final loader check at the timeout boundary", async () => {
await withFixture(async (fixture) => {
const baseCdp = fixture.services.cdp;
@@ -2259,13 +2451,17 @@ test("Page.reload reloads the current document and waits for the requested state
});
});
-test("Page.reload times out when no new document commits", async () => {
+test("Page.reload stops a reload that has not committed by its timeout", async () => {
await withFixture(async (fixture) => {
const baseCdp = fixture.services.cdp;
let nowMs = 0;
+ let held = false;
+ let stops = 0;
const task = taskForRound(fixture, "round-a", {
async cdp(method, params, sessionId, timeoutMs) {
if (method === "Page.getFrameTree") {
+ if (held)
+ throw new CdpRequestTimeoutError(method, timeoutMs, sessionId);
return {
result: {
frameTree: {
@@ -2274,7 +2470,15 @@ test("Page.reload times out when no new document commits", async () => {
},
};
}
- if (method === "Page.reload") return {};
+ if (method === "Page.reload") {
+ held = true;
+ return {};
+ }
+ if (method === "Page.stopLoading") {
+ stops += 1;
+ held = false;
+ return {};
+ }
return baseCdp(method, params, sessionId, timeoutMs);
},
now: () => nowMs,
@@ -2286,8 +2490,9 @@ test("Page.reload times out when no new document commits", async () => {
await assert.rejects(
() => page.reload({ timeout: 100, waitUntil: "commit" }),
- /page\.reload timed out after 100ms waiting for commit/,
+ /page\.reload timed out after 100ms waiting for commit; the reload had not committed and was stopped, so the Page still shows its previous document\. Retry page\.reload\(\{ timeout \}\)/,
);
+ assert.equal(stops, 1, "the pending reload is stopped");
});
});
diff --git a/package/ego-browser/src/public-api-schema.ts b/package/ego-browser/src/public-api-schema.ts
index f853f87..311b5ef 100644
--- a/package/ego-browser/src/public-api-schema.ts
+++ b/package/ego-browser/src/public-api-schema.ts
@@ -204,7 +204,7 @@ export const PUBLIC_API_SCHEMA: readonly PublicApiEntry[] = [
name: "Page.goto",
signature: "await page.goto(url, { referer?, timeout?, waitUntil? })",
summary:
- "Navigate this Page in place. Timeout errors report whether the new document committed, plus its URL and readyState when available.",
+ "Navigate this Page in place. Timeout errors report whether the new document committed, plus its URL and readyState when available. A navigation that has not committed by the timeout is stopped so the Page stays usable on its previous document.",
options: {
referer: option(
"nonEmptyString",