diff --git a/Userland/Libraries/LibWeb/HTML/Location.cpp b/Userland/Libraries/LibWeb/HTML/Location.cpp
index a181fa59fb..78e3a4126a 100644
--- a/Userland/Libraries/LibWeb/HTML/Location.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Location.cpp
@@ -372,11 +372,21 @@ void Location::reload() const
}
// https://html.spec.whatwg.org/multipage/history.html#dom-location-replace
-void Location::replace(String const& url) const
+WebIDL::ExceptionOr Location::replace(String const& url)
{
- auto& window = verify_cast(HTML::current_global_object());
- // FIXME: This needs spec compliance work.
- window.did_call_location_replace({}, url.to_deprecated_string());
+ // 1. If this's relevant Document is null, then return.
+ if (!relevant_document())
+ return {};
+
+ // 2. Parse url relative to the entry settings object. If that failed, throw a "SyntaxError" DOMException.
+ auto replace_url = entry_settings_object().parse_url(url);
+ if (!replace_url.is_valid())
+ return WebIDL::SyntaxError::create(realm(), MUST(String::formatted("Invalid URL '{}'", url)));
+
+ // 3. Location-object navigate this to the resulting URL record given "replace".
+ TRY(navigate(replace_url, HistoryHandlingBehavior::Replace));
+
+ return {};
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-location-assign
diff --git a/Userland/Libraries/LibWeb/HTML/Location.h b/Userland/Libraries/LibWeb/HTML/Location.h
index 909e650ab0..1ed9b830c7 100644
--- a/Userland/Libraries/LibWeb/HTML/Location.h
+++ b/Userland/Libraries/LibWeb/HTML/Location.h
@@ -49,7 +49,7 @@ public:
WebIDL::ExceptionOr hash() const;
WebIDL::ExceptionOr set_hash(String const&);
- void replace(String const& url) const;
+ WebIDL::ExceptionOr replace(String const& url);
void reload() const;
WebIDL::ExceptionOr assign(String const& url);
diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp
index 03e04311f3..a87a8956ae 100644
--- a/Userland/Libraries/LibWeb/HTML/Window.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Window.cpp
@@ -421,15 +421,6 @@ WebIDL::ExceptionOr> Window::open_impl(StringView url, St
return target_browsing_context->window_proxy();
}
-void Window::did_call_location_replace(Badge, DeprecatedString url)
-{
- auto* browsing_context = associated_document().browsing_context();
- if (!browsing_context)
- return;
- auto new_url = associated_document().parse_url(url);
- browsing_context->loader().load(move(new_url), FrameLoader::Type::Navigation);
-}
-
bool Window::dispatch_event(DOM::Event& event)
{
return DOM::EventDispatcher::dispatch(*this, event, true);
diff --git a/Userland/Libraries/LibWeb/HTML/Window.h b/Userland/Libraries/LibWeb/HTML/Window.h
index efde39c587..bcc323d563 100644
--- a/Userland/Libraries/LibWeb/HTML/Window.h
+++ b/Userland/Libraries/LibWeb/HTML/Window.h
@@ -95,8 +95,6 @@ public:
WebIDL::ExceptionOr> open_impl(StringView url, StringView target, StringView features);
bool has_animation_frame_callbacks() const { return m_animation_frame_callback_driver.has_callbacks(); }
- void did_call_location_replace(Badge, DeprecatedString url);
-
DOM::Event* current_event() { return m_current_event.ptr(); }
DOM::Event const* current_event() const { return m_current_event.ptr(); }
void set_current_event(DOM::Event* event);