Remove unused timestamp field

Move notification directly into history. Improve test.
This commit is contained in:
Karl Seguin
2026-07-17 09:13:33 +08:00
parent 2f4b7ec9ce
commit 0e49d6f280
4 changed files with 19 additions and 25 deletions

View File

@@ -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,

View File

@@ -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;

View File

@@ -17,9 +17,10 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
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 {

View File

@@ -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",
}, .{});
}