From 78820dd69af053e7d8d7ac3d0c8079a6c55ba989 Mon Sep 17 00:00:00 2001
From: 64579525 <17373302683@163.com>
Date: Mon, 12 Oct 2026 21:50:38 +0800
Subject: [PATCH] test(browser): wait for popup document loads before capture
---
scripts/lib/browser-popup-e2e.mjs | 65 ++++++++++++++++++++++++++-----
1 file changed, 55 insertions(+), 10 deletions(-)
diff --git a/scripts/lib/browser-popup-e2e.mjs b/scripts/lib/browser-popup-e2e.mjs
index a646e0643..fc66efeed 100644
--- a/scripts/lib/browser-popup-e2e.mjs
+++ b/scripts/lib/browser-popup-e2e.mjs
@@ -16,17 +16,28 @@ import { compareBrowserScenarios } from "../../dist/domain/browserScenarioDiff.j
import { browserScenarioCaptureSchema } from "../../dist/domain/browserScenarioCapture.js";
import { parseEvidence } from "../../dist/domain/evidence.js";
+// Readiness includes descendant document loads, so complete network capture
+// does not depend on whether an inline script runs before an iframe finishes.
const document = (path) => {
+ const icon = '';
if (path.startsWith("/nested"))
- return `
- `;
+ return `${icon}
+ `;
if (path.startsWith("/popup"))
- return `
- `;
- if (path.startsWith("/child")) return "child frame";
- return `
+ `;
+ if (path.startsWith("/child")) return `${icon}child frame`;
+ return `${icon}`;
};
@@ -74,7 +85,25 @@ const assertNetwork = (result, origin) => {
1,
`${kind} ${path} must be captured exactly once`,
);
- assert.equal(result.completeness.equality_eligible, true);
+ assert.equal(
+ result.completeness.equality_eligible,
+ true,
+ JSON.stringify({
+ limitations: result.limitations,
+ unfinished: result.events.items.filter(
+ (event) => event.kind === "request-unfinished",
+ ),
+ }),
+ );
+ assert.equal(
+ result.events.items.filter(
+ (event) =>
+ event.kind === "request-finished" &&
+ event.url?.url === origin + "/child",
+ ).length,
+ 1,
+ "child document must finish before network capture ends",
+ );
assert.equal(compareWithSelf(result).overall_status, "unchanged");
};
@@ -179,13 +208,27 @@ const verifyTransports = async (executable, origin) => {
/** Verify popup timing, selection, coverage, and shared-context isolation on Chromium. */
export async function verifyPopupEventCoverage(executable) {
+ let slowChild = true;
+ let childTimer;
+ const childStarted = Promise.withResolvers();
const server = createServer((request, response) => {
if (request.url === "/redirect") {
response.writeHead(302, { Location: "/popup" });
response.end();
} else {
response.setHeader("Content-Type", "text/html");
- response.end(document(request.url ?? "/"));
+ if (slowChild && request.url === "/child") {
+ // Keep one response open while the nested page can announce readiness.
+ // This exposes premature capture cutoff even on fast local browsers.
+ response.writeHead(200);
+ response.write(document("/child"));
+ childStarted.resolve();
+ childTimer = setTimeout(() => response.end(), 1500);
+ } else if (slowChild && request.url === "/nested") {
+ void childStarted.promise.then(() => response.end(document("/nested")));
+ } else {
+ response.end(document(request.url ?? "/"));
+ }
}
});
server.listen(0, "127.0.0.1");
@@ -198,6 +241,7 @@ export async function verifyPopupEventCoverage(executable) {
await capture(scenarioFor(executable, origin, ["network"])),
origin,
);
+ slowChild = false;
const errors = await capture(
scenarioFor(executable, origin, ["page-errors"]),
);
@@ -239,6 +283,7 @@ export async function verifyPopupEventCoverage(executable) {
stdio_mcp: true,
};
} finally {
+ clearTimeout(childTimer);
server.closeAllConnections();
await new Promise((resolve, reject) =>
server.close((error) =>