Lightpanda: the headless browser designed for AI and automation
Minor tweaks.
Karl Seguind251e7955d40
diff --git a/src/browser/frame/resource_load.zig b/src/browser/frame/resource_load.zigindex 188856f54..4c3811ae2 100644--- a/src/browser/frame/resource_load.zig+++ b/src/browser/frame/resource_load.zig@@ -130,8 +130,8 @@ pub fn beacon(frame: *Frame, in_flight: *usize, url: [:0]const u8, body: []constconst load = try root._factory.create(BeaconLoad{.root = root,- .in_flight = in_flight,.size = body.len,+ .in_flight = in_flight,});errdefer root._factory.destroy(load);@@ -151,8 +151,6 @@ pub fn beacon(frame: *Frame, in_flight: *usize, url: [:0]const u8, body: []const}, &root._http_owner);{errdefer transfer.deinit();- // In the request's header list, as fetch()'s headers are, so the CORS- // gate weighs it for a preflight.if (content_type) |ct| {try transfer.setHeader("Content-Type", ct, .{ .source = .author });}@@ -169,8 +167,8 @@ pub fn beacon(frame: *Frame, in_flight: *usize, url: [:0]const u8, body: []const// One in-flight beacon. Exactly one of done/error/shutdown runs.const BeaconLoad = struct {root: *Frame,- in_flight: *usize,size: usize,+ in_flight: *usize,fn doneCallback(ctx: *anyopaque) !void {settle(ctx);diff --git a/src/browser/webapi/Navigator.zig b/src/browser/webapi/Navigator.zigindex 020e84bee..a80ceac8e 100644--- a/src/browser/webapi/Navigator.zig+++ b/src/browser/webapi/Navigator.zig@@ -20,11 +20,9 @@ const std = @import("std");const builtin = @import("builtin");const js = @import("../js/js.zig");-const Frame = @import("../Frame.zig");const URL = @import("../URL.zig");-const resource_load = @import("../frame/resource_load.zig");+const Frame = @import("../Frame.zig");const BodyInit = @import("net/body_init.zig").BodyInit;-const Execution = js.Execution;const PluginArray = @import("PluginArray.zig");const Permissions = @import("Permissions.zig");@@ -35,6 +33,9 @@ const Geolocation = @import("geolocation/Geolocation.zig");const ServiceWorkerContainer = @import("ServiceWorkerContainer.zig");const LockManager = @import("LockManager.zig");+const Execution = js.Execution;+const resource_load = Frame.resource_load;+const Navigator = @This();comptime {@@ -53,8 +54,6 @@ _storage: StorageManager = .{},_ua_data: NavigatorUAData = .{},_service_worker: ?*ServiceWorkerContainer = null,_locks: ?*LockManager = null,-/// The bodies of this document's beacons still in flight, for the keepalive-/// quota. Allocated in the page arena on the first sendBeacon._beacon_bytes: ?*usize = null,pub const init: Navigator = .{};@@ -150,12 +149,8 @@ fn javaEnabled(_: *const Navigator) bool {const keepalive_quota = 64 * 1024;/// https://w3c.github.io/beacon/#sec-processing-model-/// The URL and data are always checked, and the return value reflects the-/// keepalive quota. The request is only sent with `--load-resources beacon`;-/// otherwise this behaves as a browser with beacons disabled would, returning-/// true without sending anything.+/// Only sent if --load-resources beacon is set.fn sendBeacon(self: *Navigator, url: []const u8, data: ?BodyInit, frame: *Frame) !bool {- // The URL parser, not the document's encoding: the query is UTF-8.const resolved = URL.resolve(frame.local_arena, frame.base(), url, .{}) catch {return frame.js.typeError("sendBeacon: invalid URL");};@@ -166,8 +161,8 @@ fn sendBeacon(self: *Navigator, url: []const u8, data: ?BodyInit, frame: *Frame)var body: []const u8 = "";var content_type: ?[]const u8 = null;if (data) |d| {- // A keepalive request can't have a ReadableStream body.if (d == .stream) {+ // A keepalive request can't have a ReadableStream body.return frame.js.typeError("sendBeacon: a ReadableStream body is not supported");}const extracted = try d.extract(frame.local_arena);@@ -175,9 +170,20 @@ fn sendBeacon(self: *Navigator, url: []const u8, data: ?BodyInit, frame: *Frame)content_type = extracted.content_type;}- // In the page arena: a beacon can outlive the iframe that sent it, and it- // gives its bytes back when it settles.+ if (frame._session.load_resources.beacon == false) {+ // Nothing is ever in flight, so only this body counts against the quota.+ if (body.len > keepalive_quota) {+ return false;+ }+ frame.page.status.noteSkipped(.beacon);+ return true;+ }++ // keep the # of bytes in-flight for the keepalive quotaconst in_flight = self._beacon_bytes orelse blk: {+ // windows can be re-used, heap allocate this so that each document+ // gets its own counter, and old beacons decrement what they counted+ // against.const counter = try frame.page_arena.create(usize);counter.* = 0;self._beacon_bytes = counter;@@ -186,11 +192,6 @@ fn sendBeacon(self: *Navigator, url: []const u8, data: ?BodyInit, frame: *Frame)if (in_flight.* + body.len > keepalive_quota) {return false;}-- if (frame._session.load_resources.beacon == false) {- frame.page.status.noteSkipped(.beacon);- return true;- }try resource_load.beacon(frame, in_flight, resolved, body, content_type);return true;}diff --git a/src/help.zon b/src/help.zonindex 959e9dc1c..1896ef568 100644--- a/src/help.zon+++ b/src/help.zon@@ -480,9 +480,8 @@\\ Defaults to stylesheet for mcp and agent, and to none of them\\ otherwise. Passing it replaces the default.\\ Allowed values:- \\ beacon Send navigator.sendBeacon requests. When disabled,- \\ sendBeacon still checks its URL and data, and- \\ returns true without sending anything.+ \\ beacon Send navigator.sendBeacon requests. Page navigation+ \\ cancels inflight beacons.\\\\ iframe When enabled, <iframe> elements are fully loaded.\\