Merge pull request #1119 from lightpanda-io/cdp_log_entry

Emit Log.addEntry
This commit is contained in:
Karl Seguin
2025-10-06 16:45:48 +08:00
committed by GitHub
4 changed files with 132 additions and 4 deletions

View File

@@ -30,6 +30,7 @@ const Session = @import("../browser/session.zig").Session;
const Page = @import("../browser/page.zig").Page;
const Incrementing = @import("../id.zig").Incrementing;
const Notification = @import("../notification.zig").Notification;
const LogInterceptor = @import("domains/log.zig").LogInterceptor;
const InterceptState = @import("domains/fetch.zig").InterceptState;
pub const URL_BASE = "chrome://newtab/";
@@ -338,6 +339,8 @@ pub fn BrowserContext(comptime CDP_T: type) type {
intercept_state: InterceptState,
log_interceptor: LogInterceptor(Self),
// When network is enabled, we'll capture the transfer.id -> body
// This is awfully memory intensive, but our underlying http client and
// its users (script manager and page) correctly do not hold the body
@@ -378,6 +381,7 @@ pub fn BrowserContext(comptime CDP_T: type) type {
.notification_arena = cdp.notification_arena.allocator(),
.intercept_state = try InterceptState.init(allocator),
.captured_responses = .empty,
.log_interceptor = LogInterceptor(Self).init(allocator, self),
};
self.node_search_list = Node.Search.List.init(allocator, &self.node_registry);
errdefer self.deinit();
@@ -389,6 +393,10 @@ pub fn BrowserContext(comptime CDP_T: type) type {
}
pub fn deinit(self: *Self) void {
// safe to call even if never registered
log.unregisterInterceptor();
self.log_interceptor.deinit();
self.inspector.deinit();
// abort all intercepted requests before closing the sesion/page
@@ -496,6 +504,18 @@ pub fn BrowserContext(comptime CDP_T: type) type {
self.cdp.browser.notification.unregister(.page_network_almost_idle, self);
}
pub fn logEnable(self: *Self) void {
log.registerInterceptor(.{
.ctx = &self.log_interceptor,
.done = LogInterceptor(Self).done,
.writer = LogInterceptor(Self).writer,
});
}
pub fn logDisable(_: *const Self) void {
log.unregisterInterceptor();
}
pub fn onPageRemove(ctx: *anyopaque, _: Notification.PageRemove) !void {
const self: *Self = @ptrCast(@alignCast(ctx));
try @import("domains/page.zig").pageRemove(self);