Skip to content

Lightpanda: the headless browser designed for AI and automation

set document._ready_state to complete on session creation

Pierre Tachoireec2719927cf4
diff --git a/src/browser/Frame.zig b/src/browser/Frame.zig
index dc683a95f..483e408f5 100644
--- a/src/browser/Frame.zig
+++ b/src/browser/Frame.zig
@@ -709,6 +709,8 @@ pub fn navigate(self: *Frame, request_url: [:0]const u8, opts: NavigateOpts) !vo
const page_scope = page.logScope();
defer page_scope.exit();
+ self.document._ready_state = .loading;
+
const is_root = self == &page.frame;
const log_data = .{
.url = request_url,
diff --git a/src/browser/Session.zig b/src/browser/Session.zig
index 79cdb6084..ab3ded6dc 100644
--- a/src/browser/Session.zig
+++ b/src/browser/Session.zig
@@ -395,6 +395,8 @@ pub fn createPage(self: *Session) !PageHandle {
const frame_id = self.nextFrameId();
const frame = try self.installNewActivePage(frame_id);
+ frame.document._ready_state = .complete;
+
// 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
diff --git a/src/browser/webapi/Document.zig b/src/browser/webapi/Document.zig
index e10fc5b0f..dc4c6e13c 100644
--- a/src/browser/webapi/Document.zig
+++ b/src/browser/webapi/Document.zig
@@ -812,14 +812,7 @@ fn whatToShow(value_: ?js.Value) !u32 {
return value.toZig(u32);
}
-fn getReadyState(self: *const Document, frame: *const Frame) []const u8 {
- // special case: protocols like CDP or webdriver use a fastpath for the default about:blank page.
- // the page is considered immediately loaded **but** the _ready_state stay waiting for internal navigation reasons.
- // So if the page is about:blank, shortcut ready_state to return complete.
- if (URL.isAboutBlank(self.getURL(frame))) {
- return "complete";
- }
-
+fn getReadyState(self: *const Document) []const u8 {
return @tagName(self._ready_state);
}