mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 07:03:29 +00:00
rename ts => timestamp, ctx => notify_ctx
This commit is contained in:
@@ -139,7 +139,7 @@ pub const Session = struct {
|
|||||||
jstypes: [Types.len]usize = undefined,
|
jstypes: [Types.len]usize = undefined,
|
||||||
|
|
||||||
// recipient of notification, passed as the first parameter to notify
|
// 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,
|
notify_func: *const fn (ctx: *anyopaque, notification: *const Notification) anyerror!void,
|
||||||
|
|
||||||
fn init(self: *Session, browser: *Browser, ctx: anytype) !void {
|
fn init(self: *Session, browser: *Browser, ctx: anytype) !void {
|
||||||
@@ -159,9 +159,9 @@ pub const Session = struct {
|
|||||||
const allocator = app.allocator;
|
const allocator = app.allocator;
|
||||||
self.* = .{
|
self.* = .{
|
||||||
.app = app,
|
.app = app,
|
||||||
.ctx = any_ctx,
|
|
||||||
.env = undefined,
|
.env = undefined,
|
||||||
.browser = browser,
|
.browser = browser,
|
||||||
|
.notify_ctx = any_ctx,
|
||||||
.inspector = undefined,
|
.inspector = undefined,
|
||||||
.notify_func = ContextStruct.notify,
|
.notify_func = ContextStruct.notify,
|
||||||
.http_client = browser.http_client,
|
.http_client = browser.http_client,
|
||||||
@@ -281,7 +281,7 @@ pub const Session = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn notify(self: *const Session, notification: *const Notification) void {
|
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 });
|
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 });
|
var request = try self.newHTTPRequest(.GET, url, .{ .navigation = true });
|
||||||
defer request.deinit();
|
defer request.deinit();
|
||||||
|
|
||||||
session.notify(&.{ .page_navigate = .{ .url = url, .ts = timestamp() } });
|
session.notify(&.{ .page_navigate = .{ .url = url, .timestamp = timestamp() } });
|
||||||
var response = try request.sendSync(.{});
|
var response = try request.sendSync(.{});
|
||||||
|
|
||||||
// would be different than self.url in the case of a redirect
|
// 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;
|
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) {
|
pub const ClickResult = union(enum) {
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ pub fn pageNavigate(bc: anytype, event: *const Notification.PageEvent) !void {
|
|||||||
.name = "init",
|
.name = "init",
|
||||||
.frameId = target_id,
|
.frameId = target_id,
|
||||||
.loaderId = loader_id,
|
.loaderId = loader_id,
|
||||||
.timestamp = event.ts,
|
.timestamp = event.timestamp,
|
||||||
}, .{ .session_id = session_id });
|
}, .{ .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);
|
std.debug.assert(bc.session.page != null);
|
||||||
|
|
||||||
var cdp = bc.cdp;
|
var cdp = bc.cdp;
|
||||||
const ts = event.ts;
|
const timestamp = event.timestamp;
|
||||||
const loader_id = bc.loader_id;
|
const loader_id = bc.loader_id;
|
||||||
const target_id = bc.target_id orelse unreachable;
|
const target_id = bc.target_id orelse unreachable;
|
||||||
const session_id = bc.session_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
|
// TODO: partially hard coded
|
||||||
try cdp.sendEvent(
|
try cdp.sendEvent(
|
||||||
"Page.domContentEventFired",
|
"Page.domContentEventFired",
|
||||||
.{ .timestamp = ts },
|
.{ .timestamp = timestamp },
|
||||||
.{ .session_id = session_id },
|
.{ .session_id = session_id },
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -244,7 +244,7 @@ pub fn pageNavigated(bc: anytype, event: *const Notification.PageEvent) !void {
|
|||||||
// TODO: partially hard coded
|
// TODO: partially hard coded
|
||||||
if (bc.page_life_cycle_events) {
|
if (bc.page_life_cycle_events) {
|
||||||
try cdp.sendEvent("Page.lifecycleEvent", LifecycleEvent{
|
try cdp.sendEvent("Page.lifecycleEvent", LifecycleEvent{
|
||||||
.timestamp = ts,
|
.timestamp = timestamp,
|
||||||
.name = "DOMContentLoaded",
|
.name = "DOMContentLoaded",
|
||||||
.frameId = target_id,
|
.frameId = target_id,
|
||||||
.loaderId = loader_id,
|
.loaderId = loader_id,
|
||||||
@@ -254,14 +254,14 @@ pub fn pageNavigated(bc: anytype, event: *const Notification.PageEvent) !void {
|
|||||||
// loadEventFired event
|
// loadEventFired event
|
||||||
try cdp.sendEvent(
|
try cdp.sendEvent(
|
||||||
"Page.loadEventFired",
|
"Page.loadEventFired",
|
||||||
.{ .timestamp = ts },
|
.{ .timestamp = timestamp },
|
||||||
.{ .session_id = session_id },
|
.{ .session_id = session_id },
|
||||||
);
|
);
|
||||||
|
|
||||||
// lifecycle DOMContentLoaded event
|
// lifecycle DOMContentLoaded event
|
||||||
if (bc.page_life_cycle_events) {
|
if (bc.page_life_cycle_events) {
|
||||||
try cdp.sendEvent("Page.lifecycleEvent", LifecycleEvent{
|
try cdp.sendEvent("Page.lifecycleEvent", LifecycleEvent{
|
||||||
.timestamp = ts,
|
.timestamp = timestamp,
|
||||||
.name = "load",
|
.name = "load",
|
||||||
.frameId = target_id,
|
.frameId = target_id,
|
||||||
.loaderId = loader_id,
|
.loaderId = loader_id,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ pub const Notification = union(enum) {
|
|||||||
page_navigated: PageEvent,
|
page_navigated: PageEvent,
|
||||||
|
|
||||||
pub const PageEvent = struct {
|
pub const PageEvent = struct {
|
||||||
ts: u32,
|
timestamp: u32,
|
||||||
url: *const URL,
|
url: *const URL,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user