Skip to content

Commit bac639a

Browse files
committed
feedback
1 parent b8fe5fb commit bac639a

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

src/browser/browser.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pub const Browser = struct {
5353

5454
const notification = try Notification.init(allocator, app.notification);
5555
app.http.client.notification = notification;
56+
app.http.client.next_request_id = 0; // Should we track ids in CDP only?
5657
errdefer notification.deinit();
5758

5859
return .{
@@ -75,6 +76,7 @@ pub const Browser = struct {
7576
self.page_arena.deinit();
7677
self.session_arena.deinit();
7778
self.transfer_arena.deinit();
79+
self.http_client.notification = null;
7880
self.notification.deinit();
7981
self.state_pool.deinit();
8082
}

src/cdp/domains/fetch.zig

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ fn disable(cmd: anytype) !void {
115115

116116
fn enable(cmd: anytype) !void {
117117
const params = (try cmd.params(EnableParam)) orelse EnableParam{};
118-
if (params.patterns.len != 0) std.debug.print("Fetch.enable: Not implemented patterns set\n", .{});
119-
if (params.handleAuthRequests) std.debug.print("Fetch.enable: Not implemented handleAuthRequests set\n", .{});
118+
if (params.patterns.len != 0) log.warn(.cdp, "Fetch.enable No patterns yet", .{});
119+
if (params.handleAuthRequests) log.warn(.cdp, "Fetch.enable No auth yet", .{});
120120

121121
const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded;
122122
try bc.fetchEnable();
@@ -170,7 +170,7 @@ pub fn requestPaused(arena: Allocator, bc: anytype, intercept: *const Notificati
170170
.networkId = try std.fmt.allocPrint(arena, "REQ-{d}", .{intercept.request.id.?}),
171171
}, .{ .session_id = session_id });
172172

173-
// TODO await either continueRequest, failRequest or fulfillRequest
173+
// Await either continueRequest, failRequest or fulfillRequest
174174
intercept.wait_for_interception.* = true;
175175
}
176176

@@ -191,7 +191,7 @@ fn continueRequest(cmd: anytype) !void {
191191
})) orelse return error.InvalidParams;
192192
if (params.postData != null or params.headers != null or params.interceptResponse) return error.NotYetImplementedParams;
193193

194-
const request_id = try id_from_request_id(params.requestId);
194+
const request_id = try idFromRequestId(params.requestId);
195195
var waiting_request = (bc.cdp.intercept_state.waiting.fetchSwapRemove(request_id) orelse return error.RequestNotFound).value;
196196

197197
// Update the request with the new parameters
@@ -203,7 +203,7 @@ fn continueRequest(cmd: anytype) !void {
203203
waiting_request.method = std.meta.stringToEnum(Method, method) orelse return error.InvalidParams;
204204
}
205205

206-
log.info(.cdp, "Request continued by intercept", .{params.requestId});
206+
log.info(.cdp, "Request continued by intercept", .{ .id = params.requestId });
207207
try bc.cdp.browser.http_client.request(waiting_request);
208208

209209
return cmd.sendResult(null, .{});
@@ -217,17 +217,15 @@ fn failRequest(cmd: anytype) !void {
217217
errorReason: ErrorReason,
218218
})) orelse return error.InvalidParams;
219219

220-
const request_id = try id_from_request_id(params.requestId);
220+
const request_id = try idFromRequestId(params.requestId);
221221
if (state.waiting.fetchSwapRemove(request_id) == null) return error.RequestNotFound;
222222

223-
log.info(.cdp, "Request aborted by intercept", .{params.errorReason});
223+
log.info(.cdp, "Request aborted by intercept", .{ .reason = params.errorReason });
224224
return cmd.sendResult(null, .{});
225225
}
226226

227227
// Get u64 from requestId which is formatted as: "INTERCEPT-{d}"
228-
fn id_from_request_id(request_id: []const u8) !u64 {
229-
return std.fmt.parseInt(u64, request_id[10..], 10) catch |err| {
230-
log.err(.cdp, "Failed to parse requestId", .{request_id});
231-
return err;
232-
};
228+
fn idFromRequestId(request_id: []const u8) !u64 {
229+
if (!std.mem.startsWith(u8, request_id, "INTERCEPT-")) return error.InvalidParams;
230+
return std.fmt.parseInt(u64, request_id[10..], 10) catch return error.InvalidParams;
233231
}

src/http/Client.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ transfer_pool: std.heap.MemoryPool(Transfer),
7878
// see ScriptManager.blockingGet
7979
blocking: Handle,
8080

81-
// To notify registered subscribers of events
81+
// To notify registered subscribers of events, the browser sets/nulls this for us.
8282
notification: ?*Notification = null,
8383

8484
// The only place this is meant to be used is in `makeRequest` BEFORE `perform`

0 commit comments

Comments
 (0)