diff --git a/Tests/LibWeb/Text/expected/HTML/WindowOrWorkerGlobalScope-reportError.txt b/Tests/LibWeb/Text/expected/HTML/WindowOrWorkerGlobalScope-reportError.txt
index 9d7a5126046..c7a49e8bc1d 100644
--- a/Tests/LibWeb/Text/expected/HTML/WindowOrWorkerGlobalScope-reportError.txt
+++ b/Tests/LibWeb/Text/expected/HTML/WindowOrWorkerGlobalScope-reportError.txt
@@ -1,5 +1,6 @@
message = Reporting an Error!
-filename =
lineno = 0
colno = 0
error = Error: Reporting an Error!
+filename URL scheme = file:
+filename URL final path segment = WindowOrWorkerGlobalScope-reportError.html
diff --git a/Tests/LibWeb/Text/input/HTML/WindowOrWorkerGlobalScope-reportError.html b/Tests/LibWeb/Text/input/HTML/WindowOrWorkerGlobalScope-reportError.html
index 64cf70b730a..e78751da48d 100644
--- a/Tests/LibWeb/Text/input/HTML/WindowOrWorkerGlobalScope-reportError.html
+++ b/Tests/LibWeb/Text/input/HTML/WindowOrWorkerGlobalScope-reportError.html
@@ -3,11 +3,13 @@
test(() => {
window.onerror = (message, filename, lineno, colno, error) => {
println(`message = ${message}`);
- println(`filename = ${filename}`);
println(`lineno = ${lineno}`);
println(`colno = ${colno}`);
println(`error = ${error}`);
-
+ // We can't simply print the filename because it is the full path to the active script, which varies between machines.
+ const filenameURL = new URL(filename);
+ println(`filename URL scheme = ${filenameURL.protocol}`);
+ println(`filename URL final path segment = ${filenameURL.pathname.split('/').pop()}`);
return true;
};
diff --git a/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp b/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp
index ecbb0ec8b71..e4010bd47e0 100644
--- a/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp
+++ b/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp
@@ -783,22 +783,30 @@ void WindowOrWorkerGlobalScopeMixin::report_error(JS::Value e)
auto error_value = e;
// 5. Let urlString be the result of applying the URL serializer to the URL record that corresponds to the resource from which script was obtained.
- // FIXME: Use the URL of the current running script.
- auto url_string = String {};
+ // NOTE: urlString is set below once we have determined whether we are dealing with a script or a module.
+ String url_string;
+ auto script_or_module_filename = [](auto const& script_or_module) {
+ return MUST(String::from_utf8(script_or_module->filename()));
+ };
// 6. If script is a classic script and script's muted errors is true, then set message to "Script error.",
// urlString to the empty string, line and col to 0, and errorValue to null.
script_or_module.visit(
- [&](const JS::NonnullGCPtr& js_script) {
+ [&](JS::NonnullGCPtr const& js_script) {
if (verify_cast(js_script->host_defined())->muted_errors() == ClassicScript::MutedErrors::Yes) {
message = "Script error."_string;
url_string = String {};
line = 0;
col = 0;
error_value = JS::js_null();
+ } else {
+ url_string = script_or_module_filename(js_script);
}
},
- [](auto const&) {});
+ [&](JS::NonnullGCPtr const& js_module) {
+ url_string = script_or_module_filename(js_module);
+ },
+ [](Empty) {});
// 7. Let notHandled be true.
auto not_handled = true;