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.
This commit is contained in:
Luke Wilde 2025-09-07 15:31:25 +01:00 committed by Alexander Kalenik
commit 05438e70f1
Notes: github-actions[bot] 2025-09-09 13:29:46 +00:00
2 changed files with 4 additions and 12 deletions

View file

@ -1944,11 +1944,8 @@ WebIDL::ExceptionOr<GC::Ref<PendingResponse>> 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 agents cookie store and httpRequests 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 httpRequests header list.

View file

@ -200,13 +200,8 @@ ErrorOr<void> 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()) {