Skip to content

Lightpanda: the headless browser designed for AI and automation

pushEntry instead of doing a full navigation initially

Muki Kiboigof6e2210023c5
diff --git a/src/server/cdp/domains/target.zig b/src/server/cdp/domains/target.zig
index 08f5c878f..e40e0795b 100644
--- a/src/server/cdp/domains/target.zig
+++ b/src/server/cdp/domains/target.zig
@@ -221,19 +221,25 @@ fn createTarget(cmd: *CDP.Command) !void {
try doAttachtoTarget(cmd, target_id);
}
- // https://html.spec.whatwg.org/multipage/document-sequences.html,
- // Create a new browsing context always produces an initial about:blank
- // Document with its own session history entry
- const encoded_url: [:0]const u8 = if (std.mem.eql(u8, "about:blank", params.url))
- "about:blank"
- else
- try URL.resolveNavigation(frame.call_arena, params.url, .{});
-
- try frame.navigate(
- encoded_url,
- .{ .reason = .address_bar, .kind = .{ .push = null } },
+ // https://html.spec.whatwg.org/multipage/document-sequences.html --
+ // Creating a new browsing context always produces an initial about:blank
+ // Document with its own session history entry, even before any real
+ // navigation happens.
+ _ = try frame._session.navigation.pushEntry(
+ frame.url,
+ .{ .source = .navigation, .value = null },
+ frame,
+ false,
);
+ if (!std.mem.eql(u8, "about:blank", params.url)) {
+ const encoded_url = try URL.resolveNavigation(frame.call_arena, params.url, .{});
+ try frame.navigate(
+ encoded_url,
+ .{ .reason = .address_bar, .kind = .{ .push = null } },
+ );
+ }
+
try cmd.sendResult(.{
.targetId = target_id,
}, .{});