From 0e49d6f280d4eb75f1bc00ac35ae8a4125512ab5 Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Fri, 17 Jul 2026 09:13:33 +0800 Subject: [PATCH] Remove unused timestamp field Move notification directly into history. Improve test. --- src/Notification.zig | 1 - src/browser/Frame.zig | 17 ----------------- src/browser/webapi/History.zig | 25 ++++++++++++++++++------- src/cdp/domains/page.zig | 1 + 4 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/Notification.zig b/src/Notification.zig index 068260f88..9368b27b6 100644 --- a/src/Notification.zig +++ b/src/Notification.zig @@ -163,7 +163,6 @@ pub const FrameNavigated = struct { // sending DOM.documentUpdated. pub const FrameNavigatedWithinDocument = struct { frame_id: u32, - timestamp: u64, url: [:0]const u8, navigation_type: NavigationType = .other, diff --git a/src/browser/Frame.zig b/src/browser/Frame.zig index 23fcfc6cb..b84fca6f7 100644 --- a/src/browser/Frame.zig +++ b/src/browser/Frame.zig @@ -33,7 +33,6 @@ const Parser = @import("parser/Parser.zig"); const h5e = @import("parser/html5ever.zig"); const CustomElementReactions = @import("CustomElementReactions.zig"); -const Notification = @import("../Notification.zig"); const URL = @import("URL.zig"); const Blob = @import("webapi/Blob.zig"); @@ -600,22 +599,6 @@ pub fn isSameOrigin(self: *const Frame, url: [:0]const u8) bool { return std.mem.eql(u8, URL.getHost(url), URL.getHost(current_origin)); } -// Notify observers of a same-document navigation (History pushState / -// replaceState, fragment change, or history traversal). Unlike navigate(), -// the document and its execution context are unchanged — only the URL moves. -pub fn notifyNavigatedWithinDocument( - self: *Frame, - url: [:0]const u8, - navigation_type: Notification.FrameNavigatedWithinDocument.NavigationType, -) void { - self._session.notification.dispatch(.frame_navigated_within_document, &.{ - .frame_id = self._frame_id, - .url = url, - .timestamp = timestamp(.monotonic), - .navigation_type = navigation_type, - }); -} - pub fn navigate(self: *Frame, request_url: [:0]const u8, opts: NavigateOpts) !void { lp.assert(self._load_state == .waiting, "frame.renavigate", .{}); const session = self._session; diff --git a/src/browser/webapi/History.zig b/src/browser/webapi/History.zig index f4a8f4546..f8eed85cc 100644 --- a/src/browser/webapi/History.zig +++ b/src/browser/webapi/History.zig @@ -17,9 +17,10 @@ // along with this program. If not, see . const std = @import("std"); -const js = @import("../js/js.zig"); +const js = @import("../js/js.zig"); const Frame = @import("../Frame.zig"); + const PopStateEvent = @import("event/PopStateEvent.zig"); const History = @This(); @@ -50,37 +51,47 @@ pub fn setScrollRestoration(self: *History, str: []const u8) void { } pub fn pushState(_: *History, state: js.Value, _: ?[]const u8, _url: ?[]const u8, frame: *Frame) !void { - const arena = frame._session.arena; + const session = frame._session; + const arena = session.arena; const url = if (_url) |u| try @import("../URL.zig").resolve(arena, frame.url, u, .{}) else try arena.dupeZ(u8, frame.url); const json = state.toJson(arena) catch return error.DataClone; - _ = try frame._session.navigation.pushEntry(url, .{ .source = .history, .value = json }, frame, true); + _ = try session.navigation.pushEntry(url, .{ .source = .history, .value = json }, frame, true); frame.url = url; // setHref == reinitializing. try frame.window._location._url.setHref(url, &frame.js.execution); - frame.notifyNavigatedWithinDocument(url, .historyApi); + session.notification.dispatch(.frame_navigated_within_document, &.{ + .url = url, + .frame_id = frame._frame_id, + .navigation_type = .historyApi, + }); } pub fn replaceState(_: *History, state: js.Value, _: ?[]const u8, _url: ?[]const u8, frame: *Frame) !void { - const arena = frame._session.arena; + const session = frame._session; + const arena = session.arena; const url = if (_url) |u| try @import("../URL.zig").resolve(arena, frame.url, u, .{}) else try arena.dupeZ(u8, frame.url); const json = state.toJson(arena) catch return error.DataClone; - _ = try frame._session.navigation.replaceEntry(url, .{ .source = .history, .value = json }, frame, true); + _ = try session.navigation.replaceEntry(url, .{ .source = .history, .value = json }, frame, true); frame.url = url; // setHref == reinitializing. try frame.window._location._url.setHref(url, &frame.js.execution); - frame.notifyNavigatedWithinDocument(url, .historyApi); + session.notification.dispatch(.frame_navigated_within_document, &.{ + .url = url, + .frame_id = frame._frame_id, + .navigation_type = .historyApi, + }); } fn goInner(delta: i32, frame: *Frame) !void { diff --git a/src/cdp/domains/page.zig b/src/cdp/domains/page.zig index a9cdaad49..fd626fc80 100644 --- a/src/cdp/domains/page.zig +++ b/src/cdp/domains/page.zig @@ -1732,5 +1732,6 @@ test "cdp.frame: history.pushState emits Page.navigatedWithinDocument" { try ctx.expectSentEvent("Page.navigatedWithinDocument", .{ .frameId = "FID-0000000001", .navigationType = "historyApi", + .url = "http://127.0.0.1:9582/next", }, .{}); }