@@ -230,14 +230,10 @@ pub fn httpRequestFail(arena: Allocator, bc: anytype, msg: *const Notification.R
230230}
231231
232232pub fn httpRequestStart (arena : Allocator , bc : anytype , msg : * const Notification.RequestStart ) ! void {
233- // Isn't possible to do a network request within a Browser (which our
234- // notification is tied to), without a page.
235- std .debug .assert (bc .session .page != null );
236-
237- var cdp = bc .cdp ;
233+ // detachTarget could be called, in which case, we still have a page doing
234+ // things, but no session.
235+ const session_id = bc .session_id orelse return ;
238236
239- // all unreachable because we _have_ to have a page.
240- const session_id = bc .session_id orelse unreachable ;
241237 const target_id = bc .target_id orelse unreachable ;
242238 const page = bc .session .currentPage () orelse unreachable ;
243239
@@ -248,22 +244,17 @@ pub fn httpRequestStart(arena: Allocator, bc: anytype, msg: *const Notification.
248244
249245 const transfer = msg .transfer ;
250246 // We're missing a bunch of fields, but, for now, this seems like enough
251- try cdp .sendEvent ("Network.requestWillBeSent" , .{ .requestId = try std .fmt .allocPrint (arena , "REQ-{d}" , .{transfer .id }), .frameId = target_id , .loaderId = bc .loader_id , .documentUrl = DocumentUrlWriter .init (& page .url .uri ), .request = TransferAsRequestWriter .init (transfer ) }, .{ .session_id = session_id });
247+ try bc . cdp .sendEvent ("Network.requestWillBeSent" , .{ .requestId = try std .fmt .allocPrint (arena , "REQ-{d}" , .{transfer .id }), .frameId = target_id , .loaderId = bc .loader_id , .documentUrl = DocumentUrlWriter .init (& page .url .uri ), .request = TransferAsRequestWriter .init (transfer ) }, .{ .session_id = session_id });
252248}
253249
254250pub fn httpResponseHeaderDone (arena : Allocator , bc : anytype , msg : * const Notification.ResponseHeaderDone ) ! void {
255- // Isn't possible to do a network request within a Browser (which our
256- // notification is tied to), without a page.
257- std .debug .assert (bc .session .page != null );
258-
259- var cdp = bc .cdp ;
260-
261- // all unreachable because we _have_ to have a page.
262- const session_id = bc .session_id orelse unreachable ;
251+ // detachTarget could be called, in which case, we still have a page doing
252+ // things, but no session.
253+ const session_id = bc .session_id orelse return ;
263254 const target_id = bc .target_id orelse unreachable ;
264255
265256 // We're missing a bunch of fields, but, for now, this seems like enough
266- try cdp .sendEvent ("Network.responseReceived" , .{
257+ try bc . cdp .sendEvent ("Network.responseReceived" , .{
267258 .requestId = try std .fmt .allocPrint (arena , "REQ-{d}" , .{msg .transfer .id }),
268259 .loaderId = bc .loader_id ,
269260 .frameId = target_id ,
@@ -272,16 +263,11 @@ pub fn httpResponseHeaderDone(arena: Allocator, bc: anytype, msg: *const Notific
272263}
273264
274265pub fn httpRequestDone (arena : Allocator , bc : anytype , msg : * const Notification.RequestDone ) ! void {
275- // Isn't possible to do a network request within a Browser (which our
276- // notification is tied to), without a page.
277- std .debug .assert (bc .session .page != null );
278-
279- var cdp = bc .cdp ;
280-
281- // all unreachable because we _have_ to have a page.
282- const session_id = bc .session_id orelse unreachable ;
266+ // detachTarget could be called, in which case, we still have a page doing
267+ // things, but no session.
268+ const session_id = bc .session_id orelse return ;
283269
284- try cdp .sendEvent ("Network.loadingFinished" , .{
270+ try bc . cdp .sendEvent ("Network.loadingFinished" , .{
285271 .requestId = try std .fmt .allocPrint (arena , "REQ-{d}" , .{msg .transfer .id }),
286272 .encodedDataLength = msg .transfer .bytes_received ,
287273 }, .{ .session_id = session_id });
0 commit comments