LibWeb: Implement cookie fetching for Workers
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run

Allows formulas to update on Google Sheets, which uses a Worker to
update them and makes cookie authenticated requests, which was failing
before this commit.

This has the limitation that it has to proxy through the WebContent
process, but that's how the current infrastructure is, which is outside
the scope of this commit.
This commit is contained in:
Luke Wilde 2025-09-07 15:32:43 +01:00 committed by Alexander Kalenik
commit 6d3fd2b543
Notes: github-actions[bot] 2025-09-09 13:29:33 +00:00
7 changed files with 32 additions and 0 deletions

View file

@ -49,10 +49,20 @@ void WorkerAgentParent::initialize(JS::Realm& realm)
auto transport = make<IPC::Transport>(move(worker_socket));
m_worker_ipc = make_ref_counted<WebWorkerClient>(move(transport));
setup_worker_ipc_callbacks(realm);
m_worker_ipc->async_start_worker(m_url, m_worker_options.type, m_worker_options.credentials, m_worker_options.name, move(data_holder), m_outside_settings->serialize(), m_agent_type);
}
void WorkerAgentParent::setup_worker_ipc_callbacks(JS::Realm& realm)
{
// NOTE: As long as WorkerAgentParent is alive, realm and m_worker_ipc will be alive.
m_worker_ipc->on_request_cookie = [realm = GC::RawRef { realm }](URL::URL const& url, Cookie::Source source) {
auto& client = Bindings::principal_host_defined_page(realm).client();
return client.page_did_request_cookie(url, source);
};
}
void WorkerAgentParent::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);

View file

@ -31,6 +31,8 @@ protected:
virtual void visit_edges(Cell::Visitor&) override;
private:
void setup_worker_ipc_callbacks(JS::Realm&);
WorkerOptions m_worker_options;
Bindings::AgentType m_agent_type { Bindings::AgentType::DedicatedWorker };
URL::URL m_url;

View file

@ -20,6 +20,13 @@ void WebWorkerClient::did_close_worker()
on_worker_close();
}
Messages::WebWorkerClient::DidRequestCookieResponse WebWorkerClient::did_request_cookie(URL::URL url, Cookie::Source source)
{
if (on_request_cookie)
return on_request_cookie(url, source);
return String {};
}
WebWorkerClient::WebWorkerClient(NonnullOwnPtr<IPC::Transport> transport)
: IPC::ConnectionToServer<WebWorkerClientEndpoint, WebWorkerServerEndpoint>(*this, move(transport))
{

View file

@ -7,6 +7,7 @@
#pragma once
#include <LibIPC/ConnectionToServer.h>
#include <LibWeb/Cookie/Cookie.h>
#include <LibWeb/Export.h>
#include <LibWeb/Worker/WebWorkerClientEndpoint.h>
#include <LibWeb/Worker/WebWorkerServerEndpoint.h>
@ -22,8 +23,10 @@ public:
explicit WebWorkerClient(NonnullOwnPtr<IPC::Transport>);
virtual void did_close_worker() override;
virtual Messages::WebWorkerClient::DidRequestCookieResponse did_request_cookie(URL::URL, Cookie::Source) override;
Function<void()> on_worker_close;
Function<String(URL::URL const&, Cookie::Source)> on_request_cookie;
IPC::File clone_transport();

View file

@ -1,3 +1,7 @@
#include <LibURL/URL.h>
#include <LibWeb/Cookie/Cookie.h>
endpoint WebWorkerClient {
did_close_worker() =|
did_request_cookie(URL::URL url, Web::Cookie::Source source) => (String cookie)
}

View file

@ -77,6 +77,11 @@ Web::CSS::PreferredMotion PageHost::preferred_motion() const
return Web::CSS::PreferredMotion::Auto;
}
String PageHost::page_did_request_cookie(URL::URL const& url, Web::Cookie::Source source)
{
return m_client.did_request_cookie(url, source);
}
void PageHost::request_file(Web::FileRequest request)
{
m_client.request_file(move(request));

View file

@ -32,6 +32,7 @@ public:
virtual Web::CSS::PreferredColorScheme preferred_color_scheme() const override;
virtual Web::CSS::PreferredContrast preferred_contrast() const override;
virtual Web::CSS::PreferredMotion preferred_motion() const override;
virtual String page_did_request_cookie(URL::URL const&, Web::Cookie::Source) override;
virtual void request_file(Web::FileRequest) override;
virtual Web::DisplayListPlayerType display_list_player_type() const override { VERIFY_NOT_REACHED(); }
virtual bool is_headless() const override { VERIFY_NOT_REACHED(); }