mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-30 15:41:48 +00:00
Emit networkIdle and networkAlmostIdle Page.lifecycleEvent
Most CDP drivers have a mechanism to wait for idle network, or an almost idle network (sometimes called networkIdle2). These are events the browser must emit. The page will now emit `networkIdle` when we are reasonably sure there's no more network activity (this requires some slight changes to request interception, since, I believe, intercepted requests should be considered). `networkAlmostIdle` is currently _always_ emitted prior to emitting `networkIdle`. We should tweak this but I can't, at a glance, think of a great heuristic for when this should be emitted.
This commit is contained in:
@@ -487,6 +487,18 @@ pub fn BrowserContext(comptime CDP_T: type) type {
|
||||
self.cdp.browser.notification.unregister(.http_request_auth_required, self);
|
||||
}
|
||||
|
||||
pub fn lifecycleEventsEnable(self: *Self) !void {
|
||||
self.page_life_cycle_events = true;
|
||||
try self.cdp.browser.notification.register(.page_network_idle, self, onPageNetworkIdle);
|
||||
try self.cdp.browser.notification.register(.page_network_almost_idle, self, onPageNetworkAlmostIdle);
|
||||
}
|
||||
|
||||
pub fn lifecycleEventsDisable(self: *Self) void {
|
||||
self.page_life_cycle_events = false;
|
||||
self.cdp.browser.notification.unregister(.page_network_idle, self);
|
||||
self.cdp.browser.notification.unregister(.page_network_almost_idle, self);
|
||||
}
|
||||
|
||||
pub fn onPageRemove(ctx: *anyopaque, _: Notification.PageRemove) !void {
|
||||
const self: *Self = @ptrCast(@alignCast(ctx));
|
||||
try @import("domains/page.zig").pageRemove(self);
|
||||
@@ -508,6 +520,16 @@ pub fn BrowserContext(comptime CDP_T: type) type {
|
||||
return @import("domains/page.zig").pageNavigated(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);
|
||||
}
|
||||
|
||||
pub fn onPageNetworkAlmostIdle(ctx: *anyopaque, msg: *const Notification.PageNetworkAlmostIdle) !void {
|
||||
const self: *Self = @ptrCast(@alignCast(ctx));
|
||||
return @import("domains/page.zig").pageNetworkAlmostIdle(self, msg);
|
||||
}
|
||||
|
||||
pub fn onHttpRequestStart(ctx: *anyopaque, msg: *const Notification.RequestStart) !void {
|
||||
const self: *Self = @ptrCast(@alignCast(ctx));
|
||||
defer self.resetNotificationArena();
|
||||
|
||||
Reference in New Issue
Block a user