LibWeb: Fire error event at Worker when script loading fails

This fixes a whole bunch of WPT timeouts for Workers which wait
for this event to arrive.
This commit is contained in:
Shannon Booth
2026-03-07 21:08:19 +01:00
committed by Tim Ledbetter
parent f6e755506d
commit 1ca68af702
Notes: github-actions[bot] 2026-03-08 12:19:22 +00:00
13 changed files with 147 additions and 6 deletions

View File

@@ -102,6 +102,11 @@ IPC::File PageHost::request_worker_agent(Web::Bindings::AgentType worker_type)
return m_client.request_worker_agent(worker_type);
}
void PageHost::did_fail_loading_worker_script()
{
m_client.async_did_fail_loading_worker_script();
}
PageHost::PageHost(ConnectionFromClient& client)
: m_client(client)
, m_page(Web::Page::create(Web::Bindings::main_thread_vm(), *this))

View File

@@ -43,6 +43,7 @@ public:
virtual bool is_headless() const override { VERIFY_NOT_REACHED(); }
virtual Queue<Web::QueuedInputEvent>& input_event_queue() override { VERIFY_NOT_REACHED(); }
virtual void report_finished_handling_input_event([[maybe_unused]] u64 page_id, [[maybe_unused]] Web::EventResult event_was_handled) override { VERIFY_NOT_REACHED(); }
void did_fail_loading_worker_script();
private:
explicit PageHost(ConnectionFromClient&);

View File

@@ -22,6 +22,7 @@
#include <LibWeb/HTML/WorkerGlobalScope.h>
#include <LibWeb/HighResolutionTime/TimeOrigin.h>
#include <LibWeb/Loader/ResourceLoader.h>
#include <WebWorker/PageHost.h>
#include <WebWorker/WorkerHost.h>
namespace WebWorker {
@@ -199,13 +200,13 @@ void WorkerHost::run(GC::Ref<Web::Page> page, Web::HTML::TransferDataEncoder mes
auto perform_fetch = Web::HTML::create_perform_the_fetch_hook(inside_settings->heap(), move(perform_fetch_function));
// In both cases, let onComplete given script be the following steps:
auto on_complete_function = [inside_settings, worker_global_scope, message_port_data = move(message_port_data), url = m_url, is_shared](GC::Ptr<Web::HTML::Script> script) mutable {
auto on_complete_function = [page, inside_settings, worker_global_scope, message_port_data = move(message_port_data), url = m_url, is_shared](GC::Ptr<Web::HTML::Script> script) mutable {
auto& realm = inside_settings->realm();
// 1. If script is null or if script's error to rethrow is non-null, then:
if (!script || !script->error_to_rethrow().is_null()) {
// FIXME: 1. Queue a global task on the DOM manipulation task source given worker's relevant global object to fire an event named error at worker.
// FIXME: Notify Worker parent through IPC to fire an error event at Worker
// 1. Queue a global task on the DOM manipulation task source given worker's relevant global object to fire an event named error at worker.
as<WebWorker::PageHost>(page->client()).did_fail_loading_worker_script();
// 2. Run the environment discarding steps for inside settings.
inside_settings->discard_environment();