@@ -176,7 +176,6 @@ fn navigate(cmd: anytype) !void {
176176 }
177177
178178 var page = bc .session .currentPage () orelse return error .PageNotLoaded ;
179- bc .loader_id = bc .cdp .loader_id_gen .next ();
180179
181180 try page .navigate (params .url , .{
182181 .reason = .address_bar ,
@@ -189,8 +188,7 @@ pub fn pageNavigate(arena: Allocator, bc: anytype, event: *const Notification.Pa
189188 // things, but no session.
190189 const session_id = bc .session_id orelse return ;
191190
192- bc .loader_id = bc .cdp .loader_id_gen .next ();
193- const loader_id = bc .loader_id ;
191+ const loader_id = try std .fmt .allocPrint (arena , "REQ-{d}" , .{event .req_id });
194192 const target_id = bc .target_id orelse unreachable ;
195193
196194 bc .reset ();
@@ -234,6 +232,30 @@ pub fn pageNavigate(arena: Allocator, bc: anytype, event: *const Notification.Pa
234232 try cdp .sendEvent ("Page.frameStartedLoading" , .{
235233 .frameId = target_id ,
236234 }, .{ .session_id = session_id });
235+ }
236+
237+ pub fn pageRemove (bc : anytype ) ! void {
238+ // The main page is going to be removed, we need to remove contexts from other worlds first.
239+ for (bc .isolated_worlds .items ) | * isolated_world | {
240+ try isolated_world .removeContext ();
241+ }
242+ }
243+
244+ pub fn pageCreated (bc : anytype , page : * Page ) ! void {
245+ for (bc .isolated_worlds .items ) | * isolated_world | {
246+ try isolated_world .createContextAndLoadPolyfills (bc .arena , page );
247+ }
248+ }
249+
250+ pub fn pageNavigated (arena : Allocator , bc : anytype , event : * const Notification.PageNavigated ) ! void {
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 ;
254+ const loader_id = try std .fmt .allocPrint (arena , "REQ-{d}" , .{event .req_id });
255+ const target_id = bc .target_id orelse unreachable ;
256+ const timestamp = event .timestamp ;
257+
258+ var cdp = bc .cdp ;
237259
238260 // Drivers are sensitive to the order of events. Some more than others.
239261 // The result for the Page.navigate seems like it _must_ come after
@@ -260,6 +282,17 @@ pub fn pageNavigate(arena: Allocator, bc: anytype, event: *const Notification.Pa
260282 }, .{ .session_id = session_id });
261283 }
262284
285+ const reason_ : ? []const u8 = switch (event .opts .reason ) {
286+ .anchor = > "anchorClick" ,
287+ .script , .history , .navigation = > "scriptInitiated" ,
288+ .form = > switch (event .opts .method ) {
289+ .GET = > "formSubmissionGet" ,
290+ .POST = > "formSubmissionPost" ,
291+ else = > unreachable ,
292+ },
293+ .address_bar = > null ,
294+ };
295+
263296 if (reason_ != null ) {
264297 try cdp .sendEvent ("Page.frameClearedScheduledNavigation" , .{
265298 .frameId = target_id ,
@@ -293,37 +326,14 @@ pub fn pageNavigate(arena: Allocator, bc: anytype, event: *const Notification.Pa
293326 false ,
294327 );
295328 }
296- }
297-
298- pub fn pageRemove (bc : anytype ) ! void {
299- // The main page is going to be removed, we need to remove contexts from other worlds first.
300- for (bc .isolated_worlds .items ) | * isolated_world | {
301- try isolated_world .removeContext ();
302- }
303- }
304-
305- pub fn pageCreated (bc : anytype , page : * Page ) ! void {
306- for (bc .isolated_worlds .items ) | * isolated_world | {
307- try isolated_world .createContextAndLoadPolyfills (bc .arena , page );
308- }
309- }
310-
311- pub fn pageNavigated (bc : anytype , event : * const Notification.PageNavigated ) ! void {
312- // detachTarget could be called, in which case, we still have a page doing
313- // things, but no session.
314- const session_id = bc .session_id orelse return ;
315- const loader_id = bc .loader_id ;
316- const target_id = bc .target_id orelse unreachable ;
317- const timestamp = event .timestamp ;
318329
319- var cdp = bc .cdp ;
320330 // frameNavigated event
321331 try cdp .sendEvent ("Page.frameNavigated" , .{
322332 .type = "Navigation" ,
323333 .frame = Frame {
324334 .id = target_id ,
325335 .url = event .url ,
326- .loaderId = bc . loader_id ,
336+ .loaderId = loader_id ,
327337 .securityOrigin = bc .security_origin ,
328338 .secureContextType = bc .secure_context_type ,
329339 },
0 commit comments