Public: anyone can read this; the crew can change it.

framesLoaded waits for each child frame to reach its address, and reports the tree it checked #17729

opened this

Merged 11h 48m ago, live in production

fix/frames-committed → main 0 commits

  • Merged. fix/frames-committed was merged into main as aa2eb4c.

Review

Sign in to review this change.
1 file changed +8 −5
test/helpers/chrome.ts +8 −5
@@ -647,7 +647,7 @@ export interface LoadedFrame {
647647
648648 /**
649649 * Load `url` in headless Chromium (with `flags`, for a test's own host names), then wait for every
650 * child frame the page has to stop loading, however it ends, and report them. A frame
650 * child frame the page has to stop loading at an address, however it ends, and report them. A frame
651651 * the browser refused (a frame policy, a blocked redirect) reports `refused`: it ended on
652652 * `chrome-error://`, which a page cannot read across origins but the browser's own tree says.
653653 * Waits on the browser's own signals, never a clock.
@@ -679,6 +679,8 @@ export async function framesLoaded(
679679 stopped.add(params.frameId);
680680 wake?.();
681681 });
682 // A frame reaching its address, or taken out by the page's script, is looked at again too.
683 for (const event of ["Page.frameNavigated", "Page.frameDetached"]) cdp.on(event, () => wake?.());
682684 const loaded = cdp.once("Page.loadEventFired");
683685 await cdp.send("Page.navigate", { url });
684686 await within(15_000, `loading ${url}`, loaded);
@@ -687,7 +689,7 @@ export async function framesLoaded(
687689 return ((frameTree.childFrames ?? []) as { frame: { id: string; url: string; unreachableUrl?: string } }[]).map((c) => ({ id: c.frame.id, url: c.frame.url, unreachable: c.frame.unreachableUrl }));
688690 };
689691 // The frame stops loading on its own signal; wait until every child present has.
690 const settled = within(30_000, "the child frames finishing", (async () => {
692 const settled = await within(30_000, "the child frames finishing", (async () => {
691693 for (;;) {
692694 // Armed before the look, so a frame that stops while the tree is being read still wakes it.
693695 const next = new Promise<void>((resolve) => {
@@ -695,12 +697,13 @@ export async function framesLoaded(
695697 });
696698 const now = await children();
697699 // A frame in the markup is in the tree by the load event; none by then means none.
698 if (now.every((c) => stopped.has(c.id))) return;
700 // A frame's first, empty document stops loading too, with no address yet.
701 if (now.every((c) => stopped.has(c.id) && c.url !== "")) return now;
699702 await next;
700703 }
701704 })());
702 await settled;
703 return (await children()).map((c) => ({ url: c.unreachable ?? c.url, refused: c.url.startsWith("chrome-error:") }));
705 // The tree that passed, not a second read: a frame swapped in since has no address yet.
706 return settled.map((c) => ({ url: c.unreachable ?? c.url, refused: c.url.startsWith("chrome-error:") }));
704707 } finally {
705708 ws?.close();
706709 proc.kill("SIGKILL");

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs