From 3fc7ffadbf542817cff523517dab5f8e4c84d76e Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Thu, 10 Apr 2025 18:27:14 +0800 Subject: [PATCH] rename ts => timestamp, ctx => notify_ctx --- src/browser/browser.zig | 10 +++++----- src/cdp/domains/page.zig | 12 ++++++------ src/notification.zig | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/browser/browser.zig b/src/browser/browser.zig index fed991bc..8181e350 100644 --- a/src/browser/browser.zig +++ b/src/browser/browser.zig @@ -139,7 +139,7 @@ pub const Session = struct { jstypes: [Types.len]usize = undefined, // recipient of notification, passed as the first parameter to notify - ctx: *anyopaque, + notify_ctx: *anyopaque, notify_func: *const fn (ctx: *anyopaque, notification: *const Notification) anyerror!void, fn init(self: *Session, browser: *Browser, ctx: anytype) !void { @@ -159,9 +159,9 @@ pub const Session = struct { const allocator = app.allocator; self.* = .{ .app = app, - .ctx = any_ctx, .env = undefined, .browser = browser, + .notify_ctx = any_ctx, .inspector = undefined, .notify_func = ContextStruct.notify, .http_client = browser.http_client, @@ -281,7 +281,7 @@ pub const Session = struct { } fn notify(self: *const Session, notification: *const Notification) void { - self.notify_func(self.ctx, notification) catch |err| { + self.notify_func(self.notify_ctx, notification) catch |err| { log.err("notify {}: {}", .{ std.meta.activeTag(notification.*), err }); }; } @@ -386,7 +386,7 @@ pub const Page = struct { var request = try self.newHTTPRequest(.GET, url, .{ .navigation = true }); defer request.deinit(); - session.notify(&.{ .page_navigate = .{ .url = url, .ts = timestamp() } }); + session.notify(&.{ .page_navigate = .{ .url = url, .timestamp = timestamp() } }); var response = try request.sendSync(.{}); // would be different than self.url in the case of a redirect @@ -428,7 +428,7 @@ pub const Page = struct { self.raw_data = arr.items; } - session.notify(&.{ .page_navigated = .{ .url = url, .ts = timestamp() } }); + session.notify(&.{ .page_navigated = .{ .url = url, .timestamp = timestamp() } }); } pub const ClickResult = union(enum) { diff --git a/src/cdp/domains/page.zig b/src/cdp/domains/page.zig index 0d928cb4..1a7bc9bd 100644 --- a/src/cdp/domains/page.zig +++ b/src/cdp/domains/page.zig @@ -198,7 +198,7 @@ pub fn pageNavigate(bc: anytype, event: *const Notification.PageEvent) !void { .name = "init", .frameId = target_id, .loaderId = loader_id, - .timestamp = event.ts, + .timestamp = event.timestamp, }, .{ .session_id = session_id }); } @@ -213,7 +213,7 @@ pub fn pageNavigated(bc: anytype, event: *const Notification.PageEvent) !void { std.debug.assert(bc.session.page != null); var cdp = bc.cdp; - const ts = event.ts; + const timestamp = event.timestamp; const loader_id = bc.loader_id; const target_id = bc.target_id orelse unreachable; const session_id = bc.session_id orelse unreachable; @@ -236,7 +236,7 @@ pub fn pageNavigated(bc: anytype, event: *const Notification.PageEvent) !void { // TODO: partially hard coded try cdp.sendEvent( "Page.domContentEventFired", - .{ .timestamp = ts }, + .{ .timestamp = timestamp }, .{ .session_id = session_id }, ); @@ -244,7 +244,7 @@ pub fn pageNavigated(bc: anytype, event: *const Notification.PageEvent) !void { // TODO: partially hard coded if (bc.page_life_cycle_events) { try cdp.sendEvent("Page.lifecycleEvent", LifecycleEvent{ - .timestamp = ts, + .timestamp = timestamp, .name = "DOMContentLoaded", .frameId = target_id, .loaderId = loader_id, @@ -254,14 +254,14 @@ pub fn pageNavigated(bc: anytype, event: *const Notification.PageEvent) !void { // loadEventFired event try cdp.sendEvent( "Page.loadEventFired", - .{ .timestamp = ts }, + .{ .timestamp = timestamp }, .{ .session_id = session_id }, ); // lifecycle DOMContentLoaded event if (bc.page_life_cycle_events) { try cdp.sendEvent("Page.lifecycleEvent", LifecycleEvent{ - .timestamp = ts, + .timestamp = timestamp, .name = "load", .frameId = target_id, .loaderId = loader_id, diff --git a/src/notification.zig b/src/notification.zig index 8f25ca62..28c5162e 100644 --- a/src/notification.zig +++ b/src/notification.zig @@ -5,7 +5,7 @@ pub const Notification = union(enum) { page_navigated: PageEvent, pub const PageEvent = struct { - ts: u32, + timestamp: u32, url: *const URL, }; };