mirror of
https://github.com/zhom/donutbrowser.git
synced 2026-10-21 06:51:24 +02:00
test: opened-tab capture
This commit is contained in:
1 parent
a340005d94
commit
64d6848990
2 files changed
+16
-2
No files matched your search
+3
-2
@@ -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);
|
||||
|
||||
@@ -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", {
|
||||
|
||||
Reference in new issue
Block a user