diff --git a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp
index 4322ee43a5..518cd8c8a5 100644
--- a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp
+++ b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp
@@ -149,6 +149,28 @@ Vector TraversableNavigable::get_all_used_history_steps() const
return sorted_steps;
}
+// https://html.spec.whatwg.org/multipage/browsing-the-web.html#getting-the-history-object-length-and-index
+TraversableNavigable::HistoryObjectLengthAndIndex TraversableNavigable::get_the_history_object_length_and_index(int step) const
+{
+ // 1. Let steps be the result of getting all used history steps within traversable.
+ auto steps = get_all_used_history_steps();
+
+ // 2. Let scriptHistoryLength be the size of steps.
+ auto script_history_length = steps.size();
+
+ // 3. Assert: steps contains step.
+ VERIFY(steps.contains_slow(step));
+
+ // 4. Let scriptHistoryIndex be the index of step in steps.
+ auto script_history_index = *steps.find_first_index(step);
+
+ // 5. Return (scriptHistoryLength, scriptHistoryIndex).
+ return HistoryObjectLengthAndIndex {
+ .script_history_length = script_history_length,
+ .script_history_index = script_history_index
+ };
+}
+
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#clear-the-forward-session-history
void TraversableNavigable::clear_the_forward_session_history()
{
diff --git a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.h b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.h
index cbfad5964f..5a92fb25b5 100644
--- a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.h
+++ b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.h
@@ -30,6 +30,12 @@ public:
bool running_nested_apply_history_step() const { return m_running_nested_apply_history_step; };
VisibilityState system_visibility_state() const { return m_system_visibility_state; };
+ struct HistoryObjectLengthAndIndex {
+ size_t script_history_length;
+ size_t script_history_index;
+ };
+ HistoryObjectLengthAndIndex get_the_history_object_length_and_index(int) const;
+
Vector get_all_used_history_steps() const;
void clear_the_forward_session_history();