Rework CDP frameIds (and loaderIds and requestIds and interceptorIds)

Our BrowsingContext currently supports 1 target. So we have a per-BC target_id.
Previously, our target had 1 "frame" - our page. So we often treated the
targetId as the frameId. But to work with frames, we need page-specific
frameIds and loaderIds.

This tries to clean up our ids (a little). frameIds are now ids derived from
a new incrementing page.id. This page.id has to be passed around (via http
Requests and through notifications) in order to properly generate messages with
a frameId.
This commit is contained in:
Karl Seguin
2026-02-18 18:52:15 +08:00
parent 5fd95788f9
commit e2a1ce623c
18 changed files with 409 additions and 296 deletions

View File

@@ -79,7 +79,7 @@ multi: *c.CURLM,
handles: Handles,
// Use to generate the next request ID
next_request_id: u64 = 0,
next_request_id: u32 = 0,
// When handles has no more available easys, requests get queued.
queue: TransferQueue,
@@ -336,6 +336,7 @@ fn fetchRobotsThenProcessRequest(self: *Client, robots_url: [:0]const u8, req: R
.method = .GET,
.headers = headers,
.blocking = false,
.page_id = req.page_id,
.cookie_jar = req.cookie_jar,
.notification = req.notification,
.resource_type = .fetch,
@@ -562,12 +563,12 @@ pub fn fulfillTransfer(self: *Client, transfer: *Transfer, status: u16, headers:
transfer._intercept_state = .fulfilled;
}
pub fn nextReqId(self: *Client) usize {
return self.next_request_id + 1;
pub fn nextReqId(self: *Client) u32 {
return self.next_request_id +% 1;
}
pub fn incrReqId(self: *Client) usize {
const id = self.next_request_id + 1;
pub fn incrReqId(self: *Client) u32 {
const id = self.next_request_id +% 1;
self.next_request_id = id;
return id;
}
@@ -1003,6 +1004,7 @@ pub const RequestCookie = struct {
};
pub const Request = struct {
page_id: u32,
method: Method,
url: [:0]const u8,
headers: Http.Headers,
@@ -1093,7 +1095,7 @@ pub const AuthChallenge = struct {
pub const Transfer = struct {
arena: ArenaAllocator,
id: usize = 0,
id: u32 = 0,
req: Request,
url: [:0]const u8,
ctx: *anyopaque, // copied from req.ctx to make it easier for callback handlers