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
Merged 11h 48m ago, live in production
fix/frames-committed → main 0 commits
1 file
changed +8
−5
test/helpers/chrome.ts +8 −5
| @@ -647,7 +647,7 @@ export interface LoadedFrame { | ||
| 647 | 647 | |
| 648 | 648 | /** |
| 649 | 649 | * 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 | |
| 651 | 651 | * the browser refused (a frame policy, a blocked redirect) reports `refused`: it ended on |
| 652 | 652 | * `chrome-error://`, which a page cannot read across origins but the browser's own tree says. |
| 653 | 653 | * Waits on the browser's own signals, never a clock. |
| @@ -679,6 +679,8 @@ export async function framesLoaded( | ||
| 679 | 679 | stopped.add(params.frameId); |
| 680 | 680 | wake?.(); |
| 681 | 681 | }); |
| 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?.()); | |
| 682 | 684 | const loaded = cdp.once("Page.loadEventFired"); |
| 683 | 685 | await cdp.send("Page.navigate", { url }); |
| 684 | 686 | await within(15_000, `loading ${url}`, loaded); |
| @@ -687,7 +689,7 @@ export async function framesLoaded( | ||
| 687 | 689 | 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 })); |
| 688 | 690 | }; |
| 689 | 691 | // 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 () => { | |
| 691 | 693 | for (;;) { |
| 692 | 694 | // Armed before the look, so a frame that stops while the tree is being read still wakes it. |
| 693 | 695 | const next = new Promise<void>((resolve) => { |
| @@ -695,12 +697,13 @@ export async function framesLoaded( | ||
| 695 | 697 | }); |
| 696 | 698 | const now = await children(); |
| 697 | 699 | // 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; | |
| 699 | 702 | await next; |
| 700 | 703 | } |
| 701 | 704 | })()); |
| 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:") })); | |
| 704 | 707 | } finally { |
| 705 | 708 | ws?.close(); |
| 706 | 709 | proc.kill("SIGKILL"); |
new above
offline