diff --git a/Userland/Libraries/LibWeb/HTML/History.cpp b/Userland/Libraries/LibWeb/HTML/History.cpp
index c0d8087c02..d45e60bc1b 100644
--- a/Userland/Libraries/LibWeb/HTML/History.cpp
+++ b/Userland/Libraries/LibWeb/HTML/History.cpp
@@ -38,6 +38,7 @@ void History::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_associated_document);
+ visitor.visit(m_state);
}
// https://html.spec.whatwg.org/multipage/history.html#dom-history-pushstate
@@ -65,6 +66,17 @@ WebIDL::ExceptionOr History::length() const
return m_length;
}
+// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-history-state
+WebIDL::ExceptionOr History::state() const
+{
+ // 1. If this's relevant global object's associated Document is not fully active, then throw a "SecurityError" DOMException.
+ if (!m_associated_document->is_fully_active())
+ return WebIDL::SecurityError::create(realm(), "Cannot perform state on a document that isn't fully active."_fly_string);
+
+ // 2. Return this's state.
+ return m_state;
+}
+
// https://html.spec.whatwg.org/multipage/history.html#dom-history-go
WebIDL::ExceptionOr History::go(long delta = 0)
{
diff --git a/Userland/Libraries/LibWeb/HTML/History.h b/Userland/Libraries/LibWeb/HTML/History.h
index 90b3897c5a..1c6bd911da 100644
--- a/Userland/Libraries/LibWeb/HTML/History.h
+++ b/Userland/Libraries/LibWeb/HTML/History.h
@@ -28,10 +28,13 @@ public:
WebIDL::ExceptionOr back();
WebIDL::ExceptionOr forward();
WebIDL::ExceptionOr length() const;
+ WebIDL::ExceptionOr state() const;
u64 m_index { 0 };
u64 m_length { 0 };
+ void set_state(JS::Value s) { m_state = s; }
+
private:
History(JS::Realm&, DOM::Document&);
@@ -41,6 +44,7 @@ private:
WebIDL::ExceptionOr shared_history_push_replace_state(JS::Value data, Optional const& url, HistoryHandlingBehavior);
JS::NonnullGCPtr m_associated_document;
+ JS::Value m_state { JS::js_null() };
};
bool can_have_its_url_rewritten(DOM::Document const& document, AK::URL const& target_url);
diff --git a/Userland/Libraries/LibWeb/HTML/History.idl b/Userland/Libraries/LibWeb/HTML/History.idl
index 000655737d..f1800e724e 100644
--- a/Userland/Libraries/LibWeb/HTML/History.idl
+++ b/Userland/Libraries/LibWeb/HTML/History.idl
@@ -3,7 +3,7 @@
interface History {
readonly attribute unsigned long length;
// FIXME: attribute ScrollRestoration scrollRestoration;
- // FIXME: readonly attribute any state;
+ readonly attribute any state;
undefined go(optional long delta = 0);
undefined back();
undefined forward();