test: opened-tab capture

This commit is contained in:
zhom committed 2026-10-19 16:15:58 +04:00
1 parent a340005d94
commit 64d6848990
2 files changed
+16 -2

No files matched your search

+3 -2
View File
@@ -33,7 +33,7 @@ export class CdpClient {
});
}
static async connect(port, { timeoutMs = 30_000 } = {}) {
static async connect(port, { timeoutMs = 30_000, match = () => true } = {}) {
assert.equal(
typeof WebSocket,
"function",
@@ -49,7 +49,8 @@ export class CdpClient {
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const targets = await response.json();
const target = targets.find(
(item) => item.type === "page" && item.webSocketDebuggerUrl,
(item) =>
item.type === "page" && item.webSocketDebuggerUrl && match(item),
);
if (!target) throw new Error("no debuggable page target");
const socket = new WebSocket(target.webSocketDebuggerUrl);
+13
View File
@@ -1177,6 +1177,19 @@ test("real Wayfern fingerprinting, terms, API automation, CDP, cookies, and proc
},
{ timeoutMs: 20_000, description: "API-opened Wayfern target" },
);
// The tab's own first load can start before the capture attaches to it;
// what the tab sends once it is open is captured.
const openedTab = await CdpClient.connect(
launched.value.remote_debugging_port,
{ match: (target) => target.url.includes("/opened-via-api") },
);
try {
await openedTab.evaluate(
"fetch('/api/echo?from=opened-via-api').then((response) => response.text())",
);
} finally {
openedTab.close();
}
const capturedRequest = await app.waitFor(
async () => {
const listed = await app.invoke("list_network_requests", {