Lightpanda: the headless browser designed for AI and automation
replace about:blank strin comparison with URL.isAboutBlank call
Pierre Tachoireaca2538d9979
diff --git a/src/browser/Frame.zig b/src/browser/Frame.zigindex caebbfc70..dc683a95f 100644--- a/src/browser/Frame.zig+++ b/src/browser/Frame.zig@@ -606,7 +606,7 @@ pub fn navigationBase(self: *const Frame) [:0]const u8 {var maybe_not_blank_frame = self;while (true) {const maybe_base = maybe_not_blank_frame.base();- if (std.mem.eql(u8, maybe_base, "about:blank") == false) {+ if (URL.isAboutBlank(maybe_base) == false) {return maybe_base;}// The orelse here is probably an invalid case, but there isn't@@ -696,7 +696,7 @@ fn isPotentiallyTrustworthy(self: *const Frame) bool {// No origin: either an opaque one (data:, which is never trustworthy), a// file: document, or an about:blank/srcdoc with nothing to inherit from.const url = self.url;- return std.mem.eql(u8, url, "about:blank") or std.mem.eql(u8, url, "about:srcdoc") or std.mem.startsWith(u8, url, "file:");+ return URL.isAboutBlank(url) or std.mem.eql(u8, url, "about:srcdoc") or std.mem.startsWith(u8, url, "file:");}pub fn navigate(self: *Frame, request_url: [:0]const u8, opts: NavigateOpts) !void {@@ -726,7 +726,7 @@ pub fn navigate(self: *Frame, request_url: [:0]const u8, opts: NavigateOpts) !voconst http_client = &session.browser.http_client;// Handle synthetic navigations: about:blank, about:srcdoc and blob: URLs- const is_about_blank = std.mem.eql(u8, "about:blank", request_url);+ const is_about_blank = URL.isAboutBlank(request_url);const is_srcdoc = !is_about_blank and std.mem.eql(u8, "about:srcdoc", request_url);const is_blob = !is_about_blank and !is_srcdoc and std.mem.startsWith(u8, request_url, "blob:");@@ -999,7 +999,7 @@ fn scheduleNavigationWithArena(originator: *Frame, arena: *lp.Arena, request_urlbreak :blk .{ try arena.dupeSentinel(u8, request_url, 0), false };}- if (std.mem.eql(u8, request_url, "about:blank")) {+ if (URL.isAboutBlank(request_url)) {// navigate will handle this special casebreak :blk .{ "about:blank", true };}@@ -2181,7 +2181,7 @@ pub fn iframeAddedCallback(self: *Frame, iframe: *IFrame) !void {});const url = blk: {- if (std.mem.eql(u8, src, "about:blank")) {+ if (URL.isAboutBlank(src)) {break :blk "about:blank"; // navigate will handle this special case}if (std.mem.eql(u8, src, "about:srcdoc")) {@@ -2273,14 +2273,14 @@ pub fn openPopup(self: *Frame, opts: OpenPopupOpts) !*Frame {if (opts.url.len == 0) {break :blk "about:blank";}- if (std.mem.eql(u8, opts.url, "about:blank")) {+ if (URL.isAboutBlank(opts.url)) {break :blk "about:blank";}const frame_base = base_blk: {var frame = self;while (true) {const maybe_base = frame.base();- if (!std.mem.eql(u8, maybe_base, "about:blank")) {+ if (URL.isAboutBlank(maybe_base) == false) {break :base_blk maybe_base;}frame = frame.parent orelse break :base_blk "";diff --git a/src/browser/Session.zig b/src/browser/Session.zigindex 29ced435f..79cdb6084 100644--- a/src/browser/Session.zig+++ b/src/browser/Session.zig@@ -29,6 +29,7 @@ const Factory = @import("Factory.zig");const EventTarget = @import("webapi/EventTarget.zig");const Navigation = @import("webapi/navigation/Navigation.zig");+const URL = @import("URL.zig");const Page = @import("Page.zig");const Frame = @import("Frame.zig");const Browser = @import("Browser.zig");@@ -912,7 +913,7 @@ pub fn initiateRootNavigation(self: *Session, frame_id: u32, url: [:0]const u8,// therefore no frameHeaderDoneCallback to commit a pending Page. Swap the// active Page immediately instead of allocating a pending one that would// never be promoted, leaving the previous document in place (issue #2363).- if (std.mem.eql(u8, "about:blank", url) or std.mem.startsWith(u8, url, "blob:")) {+ if (URL.isAboutBlank(url) or std.mem.startsWith(u8, url, "blob:")) {return self.replaceRootImmediate(frame_id, url, opts);}diff --git a/src/server/cdp/domains/target.zig b/src/server/cdp/domains/target.zigindex 5ec9a2db2..7c80905da 100644--- a/src/server/cdp/domains/target.zig+++ b/src/server/cdp/domains/target.zig@@ -238,7 +238,7 @@ fn createTarget(cmd: *CDP.Command) !void {try doAttachtoTarget(cmd, target_id);}- if (!std.mem.eql(u8, "about:blank", params.url)) {+ if (URL.isAboutBlank(params.url) == false) {const encoded_url = try URL.resolveNavigation(frame.call_arena, params.url, .{});try frame.navigate(encoded_url,