From 05438e70f1a6f006ad7f0c5f5685e6f5d5eb357c Mon Sep 17 00:00:00 2001 From: Luke Wilde Date: Sun, 7 Sep 2025 15:31:25 +0100 Subject: [PATCH] LibWeb: Receive cookies through principal_host_defined_page Previously we depended on an associated document on the ESO to get to the page, but Workers do not have documents. However, we can simply get to the page with `principal_host_defined_page`, removing the issue. --- Libraries/LibWeb/Fetch/Fetching/Fetching.cpp | 7 ++----- Libraries/LibWeb/WebSockets/WebSocket.cpp | 9 ++------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp index d7be18ccb27..1df8e1242af 100644 --- a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp +++ b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp @@ -1944,11 +1944,8 @@ WebIDL::ExceptionOr> http_network_or_cache_fetch(JS::Re // 1. Let cookies be the result of running the "cookie-string" algorithm (see section 5.4 of [COOKIES]) // with the user agent’s cookie store and httpRequest’s current URL. auto cookies = ([&] { - // FIXME: Getting to the page client reliably is way too complicated, and going via the document won't work in workers. - auto document = Bindings::principal_host_defined_environment_settings_object(HTML::principal_realm(realm)).responsible_document(); - if (!document) - return String {}; - return document->page().client().page_did_request_cookie(http_request->current_url(), Cookie::Source::Http); + auto& page = Bindings::principal_host_defined_page(HTML::principal_realm(realm)); + return page.client().page_did_request_cookie(http_request->current_url(), Cookie::Source::Http); })(); // 2. If cookies is not the empty string, then append (`Cookie`, cookies) to httpRequest’s header list. diff --git a/Libraries/LibWeb/WebSockets/WebSocket.cpp b/Libraries/LibWeb/WebSockets/WebSocket.cpp index f841fd9f0c7..1f188ab6215 100644 --- a/Libraries/LibWeb/WebSockets/WebSocket.cpp +++ b/Libraries/LibWeb/WebSockets/WebSocket.cpp @@ -200,13 +200,8 @@ ErrorOr WebSocket::establish_web_socket_connection(URL::URL const& url_rec HTTP::HeaderMap additional_headers; auto cookies = ([&] { - // FIXME: Getting to the page client reliably is way too complicated, and going via the document won't work in workers. - auto document = client.responsible_document(); - if (!document) - return String {}; - - // NOTE: The WebSocket handshake is sent as an HTTP request, so the source should be Http. - return document->page().client().page_did_request_cookie(url_record, Cookie::Source::Http); + auto& page = Bindings::principal_host_defined_page(HTML::principal_realm(realm())); + return page.client().page_did_request_cookie(url_record, Cookie::Source::Http); })(); if (!cookies.is_empty()) {