Lightpanda: the headless browser designed for AI and automation
`Worker`: inherit site-for-cookies from the creating document
Halil Durak9ddf6ad02a79
diff --git a/src/browser/ScriptManagerBase.zig b/src/browser/ScriptManagerBase.zigindex 0b1fd0bc2..9bb1731d5 100644--- a/src/browser/ScriptManagerBase.zig+++ b/src/browser/ScriptManagerBase.zig@@ -84,7 +84,7 @@ pub const Owner = union(enum) {pub fn siteForCookies(self: Owner) Cookie.SiteForCookies {return switch (self) {.frame => |frame| frame.siteForCookies(),- .worker => |worker| .{ .url = worker.url },+ .worker => |worker| worker.site_for_cookies,};}};diff --git a/src/browser/js/Execution.zig b/src/browser/js/Execution.zigindex 7d30f219b..118583214 100644--- a/src/browser/js/Execution.zig+++ b/src/browser/js/Execution.zig@@ -133,11 +133,11 @@ pub fn origin(self: *const Execution) ?[]const u8 {};}-// a Worker's is its own URL; `Frame` prefers its ancestor chain.+// a Worker inherits its creating document's; `Frame` walks its ancestor chain.pub fn siteForCookies(self: *const Execution) Cookie.SiteForCookies {return switch (self.js.global) {.frame => |frame| frame.siteForCookies(),- .worker => |worker| .{ .url = worker.url },+ .worker => |worker| worker.site_for_cookies,};}diff --git a/src/browser/webapi/SharedWorkerGlobalScope.zig b/src/browser/webapi/SharedWorkerGlobalScope.zigindex 550c3061b..2a38832dc 100644--- a/src/browser/webapi/SharedWorkerGlobalScope.zig+++ b/src/browser/webapi/SharedWorkerGlobalScope.zig@@ -108,7 +108,7 @@ pub fn init(frame: *Frame, url: [:0]const u8, name: []const u8, worker_type: Wor.loader_id = self._loader_id,.resource_type = .script,.cookie_jar = &session.cookie_jar,- .cookie_origin = .{ .url = owned_url },+ .cookie_origin = proto.site_for_cookies,.notification = session.notification,.header_callback = httpHeaderCallback,.data_callback = httpDataCallback,diff --git a/src/browser/webapi/Worker.zig b/src/browser/webapi/Worker.zigindex 65c69bacc..85440d747 100644--- a/src/browser/webapi/Worker.zig+++ b/src/browser/webapi/Worker.zig@@ -107,7 +107,7 @@ pub fn init(url: []const u8, options: ?WorkerOptions, frame: *Frame) !*Worker {.loader_id = self._loader_id,.resource_type = .script,.cookie_jar = &session.cookie_jar,- .cookie_origin = .{ .url = resolved_url },+ .cookie_origin = frame.siteForCookies(),.notification = session.notification,.header_callback = httpHeaderCallback,.data_callback = httpDataCallback,diff --git a/src/browser/webapi/WorkerGlobalScope.zig b/src/browser/webapi/WorkerGlobalScope.zigindex 78b2fdb04..330b16c19 100644--- a/src/browser/webapi/WorkerGlobalScope.zig+++ b/src/browser/webapi/WorkerGlobalScope.zig@@ -46,6 +46,7 @@ const ErrorEvent = @import("event/ErrorEvent.zig");const Fetch = @import("net/Fetch.zig");const idb = @import("storage/idb/idb.zig");const CookieStore = @import("storage/CookieStore.zig");+const Cookie = @import("storage/Cookie.zig");const MessagePort = @import("MessagePort.zig");const SharedWorkerGlobalScope = @import("SharedWorkerGlobalScope.zig");const DedicatedWorkerGlobalScope = @import("DedicatedWorkerGlobalScope.zig");@@ -78,6 +79,8 @@ local_arena: Allocator,url: [:0]const u8,// Same-origin constraint: a worker's origin is inherited from its parent frame.origin: ?[]const u8 = null,+// Inherited from the creating frame, like origin.+site_for_cookies: Cookie.SiteForCookies,buf: [1024]u8 = undefined, // same size as frame.buf// Document charset (matches Page.charset). Workers default to UTF-8.charset: []const u8 = "UTF-8",@@ -148,6 +151,10 @@ pub fn init(.url = url,.arena = arena,.origin = frame.origin,+ .site_for_cookies = switch (frame.siteForCookies()) {+ .none => .none,+ .url => |u| .{ .url = try arena.dupeZ(u8, u) },+ },.js = undefined,._call_arena = call_arena,._local_arena = local_arena,@@ -423,7 +430,7 @@ fn importScript(self: *WorkerGlobalScope, arena: Allocator, url: [:0]const u8) !.document_frame_id = self._frame._frame_id,.loader_id = self._loader_id,.cookie_jar = &session.cookie_jar,- .cookie_origin = .{ .url = self.url },+ .cookie_origin = self.site_for_cookies,.resource_type = .script,.notification = session.notification,.shutdown_callback = HttpClient.noopShutdown, // syncRequest installs its own