mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-04-01 18:06:46 +00:00
Improve/Fix CDP navigation event order
These changes all better align with chrome's event ordering/timing. There are two big changes. The first is that our internal page_navigated event, which is kind of our heavy hitter, is sent once the header is received as opposed to (much later) on document load. The main goal of this internal event is to trigger the "Page.frameNavigated" CDP event which is meant to happen once the URL is committed, which _is_ on header response. To accommodate this earlier trigger, new explicit events for DOMContentLoaded and load have be added. This drastically changes the flow of events as things go from: Start Page Navigation Response Received Start Frame Navigation Response Received End Frame Navigation End Page Navigation context clear + reset DOMContentLoaded Loaded TO: Start Page Navigation Response Received End Page Navigation context clear + reset Start Frame Navigation Response Received End Frame Navigation DOMContentLoaded Loaded So not only does it remove the nesting, but it ensures that the context are cleared and reset once the main page's navigation is locked in, and before any frame is created.
This commit is contained in:
@@ -432,6 +432,8 @@ pub fn BrowserContext(comptime CDP_T: type) type {
|
||||
try notification.register(.page_navigate, self, onPageNavigate);
|
||||
try notification.register(.page_navigated, self, onPageNavigated);
|
||||
try notification.register(.page_frame_created, self, onPageFrameCreated);
|
||||
try notification.register(.page_dom_content_loaded, self, onPageDOMContentLoaded);
|
||||
try notification.register(.page_loaded, self, onPageLoaded);
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Self) void {
|
||||
@@ -607,6 +609,16 @@ pub fn BrowserContext(comptime CDP_T: type) type {
|
||||
return @import("domains/page.zig").pageFrameCreated(self, msg);
|
||||
}
|
||||
|
||||
pub fn onPageDOMContentLoaded(ctx: *anyopaque, msg: *const Notification.PageDOMContentLoaded) !void {
|
||||
const self: *Self = @ptrCast(@alignCast(ctx));
|
||||
return @import("domains/page.zig").pageDOMContentLoaded(self, msg);
|
||||
}
|
||||
|
||||
pub fn onPageLoaded(ctx: *anyopaque, msg: *const Notification.PageLoaded) !void {
|
||||
const self: *Self = @ptrCast(@alignCast(ctx));
|
||||
return @import("domains/page.zig").pageLoaded(self, msg);
|
||||
}
|
||||
|
||||
pub fn onPageNetworkIdle(ctx: *anyopaque, msg: *const Notification.PageNetworkIdle) !void {
|
||||
const self: *Self = @ptrCast(@alignCast(ctx));
|
||||
return @import("domains/page.zig").pageNetworkIdle(self, msg);
|
||||
|
||||
Reference in New Issue
Block a user