Emit networkIdle and networkAlmostIdle Page.lifecycleEvent

Most CDP drivers have a mechanism to wait for idle network, or an almost idle
network (sometimes called networkIdle2). These are events the browser must emit.

The page will now emit `networkIdle` when we are reasonably sure there's no more
network activity (this requires some slight changes to request interception,
since, I believe, intercepted requests should be considered).

`networkAlmostIdle` is currently _always_ emitted prior to emitting
`networkIdle`. We should tweak this but I can't, at a glance, think of a great
heuristic for when this should be emitted.
This commit is contained in:
Karl Seguin
2025-09-04 16:28:12 +08:00
parent 7fdc857326
commit 5dda86bf4a
6 changed files with 163 additions and 21 deletions

View File

@@ -261,7 +261,7 @@ fn continueRequest(cmd: anytype) !void {
transfer.req.body = body;
}
try bc.cdp.browser.http_client.process(transfer);
try bc.cdp.browser.http_client.continueTransfer(transfer);
return cmd.sendResult(null, .{});
}
@@ -311,7 +311,7 @@ fn continueWithAuth(cmd: anytype) !void {
);
transfer.reset();
try bc.cdp.browser.http_client.process(transfer);
try bc.cdp.browser.http_client.continueTransfer(transfer);
return cmd.sendResult(null, .{});
}
@@ -352,7 +352,7 @@ fn fulfillRequest(cmd: anytype) !void {
body = buf;
}
try transfer.fulfill(params.responseCode, params.responseHeaders orelse &.{}, body);
try bc.cdp.browser.http_client.fulfillTransfer(transfer, params.responseCode, params.responseHeaders orelse &.{}, body);
return cmd.sendResult(null, .{});
}
@@ -368,7 +368,7 @@ fn failRequest(cmd: anytype) !void {
const request_id = try idFromRequestId(params.requestId);
const transfer = intercept_state.remove(request_id) orelse return error.RequestNotFound;
defer transfer.abort();
defer bc.cdp.browser.http_client.abortTransfer(transfer);
log.info(.cdp, "request intercept", .{
.state = "fail",