cdp: use same value for requestId and loaderId

For all events regarding an HTTP request, the values of requestId
and loaderId must be the same.
This commit is contained in:
Pierre Tachoire
2025-12-12 17:04:18 +01:00
parent e2682ab9fe
commit 26827efe34
6 changed files with 55 additions and 23 deletions

View File

@@ -243,11 +243,12 @@ pub fn httpRequestStart(arena: Allocator, bc: anytype, msg: *const Notification.
}
const transfer = msg.transfer;
const loader_id = try std.fmt.allocPrint(arena, "REQ-{d}", .{transfer.id});
// We're missing a bunch of fields, but, for now, this seems like enough
try bc.cdp.sendEvent("Network.requestWillBeSent", .{
.requestId = try std.fmt.allocPrint(arena, "REQ-{d}", .{transfer.id}),
.requestId = loader_id,
.frameId = target_id,
.loaderId = bc.loader_id,
.loaderId = loader_id,
.type = msg.transfer.req.resource_type.string(),
.documentURL = DocumentUrlWriter.init(&page.url.uri),
.request = TransferAsRequestWriter.init(transfer),
@@ -263,11 +264,14 @@ pub fn httpResponseHeaderDone(arena: Allocator, bc: anytype, msg: *const Notific
const session_id = bc.session_id orelse return;
const target_id = bc.target_id orelse unreachable;
const transfer = msg.transfer;
const loader_id = try std.fmt.allocPrint(arena, "REQ-{d}", .{transfer.id});
// We're missing a bunch of fields, but, for now, this seems like enough
try bc.cdp.sendEvent("Network.responseReceived", .{
.requestId = try std.fmt.allocPrint(arena, "REQ-{d}", .{msg.transfer.id}),
.loaderId = bc.loader_id,
.requestId = loader_id,
.frameId = target_id,
.loaderId = loader_id,
.response = TransferAsResponseWriter.init(arena, msg.transfer),
.hasExtraInfo = false, // TODO change after adding Network.responseReceivedExtraInfo
}, .{ .session_id = session_id });

View File

@@ -176,7 +176,6 @@ fn navigate(cmd: anytype) !void {
}
var page = bc.session.currentPage() orelse return error.PageNotLoaded;
bc.loader_id = bc.cdp.loader_id_gen.next();
try page.navigate(params.url, .{
.reason = .address_bar,
@@ -184,13 +183,12 @@ fn navigate(cmd: anytype) !void {
});
}
pub fn pageNavigate(bc: anytype, event: *const Notification.PageNavigate) !void {
pub fn pageNavigate(arena: Allocator, bc: anytype, event: *const Notification.PageNavigate) !void {
// detachTarget could be called, in which case, we still have a page doing
// things, but no session.
const session_id = bc.session_id orelse return;
bc.loader_id = bc.cdp.loader_id_gen.next();
const loader_id = bc.loader_id;
const loader_id = try std.fmt.allocPrint(arena, "REQ-{d}", .{event.req_id});
const target_id = bc.target_id orelse unreachable;
bc.reset();
@@ -253,7 +251,7 @@ pub fn pageNavigated(arena: Allocator, bc: anytype, event: *const Notification.P
// detachTarget could be called, in which case, we still have a page doing
// things, but no session.
const session_id = bc.session_id orelse return;
const loader_id = bc.loader_id;
const loader_id = try std.fmt.allocPrint(arena, "REQ-{d}", .{event.req_id});
const target_id = bc.target_id orelse unreachable;
const timestamp = event.timestamp;
@@ -335,7 +333,7 @@ pub fn pageNavigated(arena: Allocator, bc: anytype, event: *const Notification.P
.frame = Frame{
.id = target_id,
.url = event.url,
.loaderId = bc.loader_id,
.loaderId = loader_id,
.securityOrigin = bc.security_origin,
.secureContextType = bc.secure_context_type,
},