add layers to HttpClient

This commit is contained in:
Muki Kiboigo
2026-04-01 08:11:28 -07:00
parent c02a966776
commit 5bb86b77fb
4 changed files with 939 additions and 1012 deletions

View File

@@ -260,14 +260,14 @@ pub const Client = struct {
fn start(self: *Client) void {
const http = self.http;
http.cdp_client = .{
http.setCdpClient(.{
.socket = self.ws.socket,
.ctx = self,
.blocking_read_start = Client.blockingReadStart,
.blocking_read = Client.blockingRead,
.blocking_read_end = Client.blockingReadStop,
};
defer http.cdp_client = null;
});
defer http.setCdpClient(null);
self.httpLoop(http) catch |err| {
log.err(.app, "CDP client loop", .{ .err = err });

File diff suppressed because it is too large Load Diff

View File

@@ -137,7 +137,7 @@ fn _tick(self: *Runner, comptime is_cdp: bool, opts: TickOpts) !CDPTickResult {
.pre, .raw, .text, .image => {
// The main page hasn't started/finished navigating.
// There's no JS to run, and no reason to run the scheduler.
if (http_client.active == 0 and (comptime is_cdp) == false) {
if (http_client.active() == 0 and (comptime is_cdp) == false) {
// haven't started navigating, I guess.
return .done;
}
@@ -171,8 +171,8 @@ fn _tick(self: *Runner, comptime is_cdp: bool, opts: TickOpts) !CDPTickResult {
// Each call to this runs scheduled load events.
try page.dispatchLoad();
const http_active = http_client.active;
const total_network_activity = http_active + http_client.intercepted;
const http_active = http_client.active();
const total_network_activity = http_active + http_client.intercepted();
if (page._notified_network_almost_idle.check(total_network_activity <= 2)) {
page.notifyNetworkAlmostIdle();
}
@@ -185,7 +185,7 @@ fn _tick(self: *Runner, comptime is_cdp: bool, opts: TickOpts) !CDPTickResult {
// because is_cdp is true, and that can only be
// the case when interception isn't possible.
if (comptime IS_DEBUG) {
std.debug.assert(http_client.intercepted == 0);
std.debug.assert(http_client.intercepted() == 0);
}
if (browser.hasBackgroundTasks()) {

View File

@@ -139,8 +139,8 @@ fn setLifecycleEventsEnabled(cmd: *CDP.Command) !void {
try sendPageLifecycle(bc, "load", now, frame_id, loader_id);
const http_client = page._session.browser.http_client;
const http_active = http_client.active;
const total_network_activity = http_active + http_client.intercepted;
const http_active = http_client.active();
const total_network_activity = http_active + http_client.intercepted();
if (page._notified_network_almost_idle.check(total_network_activity <= 2)) {
try sendPageLifecycle(bc, "networkAlmostIdle", now, frame_id, loader_id);
}