diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp
index 26412944fa..083c25371c 100644
--- a/Userland/Libraries/LibWeb/HTML/Window.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Window.cpp
@@ -952,7 +952,6 @@ WebIDL::ExceptionOr Window::initialize_web_interfaces(Badge Window::history() const
return associated_document().history();
}
+// https://html.spec.whatwg.org/multipage/interaction.html#dom-window-focus
+void Window::focus()
+{
+ // 1. Let current be this Window object's navigable.
+ auto* current = browsing_context();
+
+ // 2. If current is null, then return.
+ if (!current)
+ return;
+
+ // 3. Run the focusing steps with current.
+ // FIXME: We should pass in the browsing context itself instead of the active document, however the focusing steps don't currently accept browsing contexts.
+ // Passing in a browsing context always makes it resolve to its active document for focus, so this is fine for now.
+ run_focusing_steps(current->active_document());
+
+ // FIXME: 4. If current is a top-level traversable, user agents are encouraged to trigger some sort of notification to
+ // indicate to the user that the page is attempting to gain focus.
+}
+
// https://html.spec.whatwg.org/multipage/window-object.html#dom-frames
JS::NonnullGCPtr Window::frames() const
{
@@ -1615,28 +1633,6 @@ JS_DEFINE_NATIVE_FUNCTION(Window::cancel_idle_callback)
return JS::js_undefined();
}
-// https://html.spec.whatwg.org/multipage/interaction.html#dom-window-focus
-JS_DEFINE_NATIVE_FUNCTION(Window::focus)
-{
- auto* impl = TRY(impl_from(vm));
-
- // 1. Let current be this Window object's browsing context.
- auto* current = impl->browsing_context();
-
- // 2. If current is null, then return.
- if (!current)
- return JS::js_undefined();
-
- // 3. Run the focusing steps with current.
- // FIXME: We should pass in the browsing context itself instead of the active document, however the focusing steps don't currently accept browsing contexts.
- // Passing in a browsing context always makes it resolve to its active document for focus, so this is fine for now.
- run_focusing_steps(current->active_document());
-
- // FIXME: 4. If current is a top-level browsing context, user agents are encouraged to trigger some sort of notification to indicate to the user that the page is attempting to gain focus.
-
- return JS::js_undefined();
-}
-
// https://html.spec.whatwg.org/multipage/window-object.html#number-of-document-tree-child-browsing-contexts
size_t Window::document_tree_child_browsing_context_count() const
{
diff --git a/Userland/Libraries/LibWeb/HTML/Window.h b/Userland/Libraries/LibWeb/HTML/Window.h
index b95a6ef520..335e6c1e18 100644
--- a/Userland/Libraries/LibWeb/HTML/Window.h
+++ b/Userland/Libraries/LibWeb/HTML/Window.h
@@ -140,6 +140,7 @@ public:
void set_name(String const&);
JS::NonnullGCPtr location() const;
JS::NonnullGCPtr history() const;
+ void focus();
JS::NonnullGCPtr frames() const;
u32 length() const;
@@ -256,7 +257,6 @@ private:
JS_DECLARE_NATIVE_FUNCTION(clear_timeout);
JS_DECLARE_NATIVE_FUNCTION(request_animation_frame);
JS_DECLARE_NATIVE_FUNCTION(cancel_animation_frame);
- JS_DECLARE_NATIVE_FUNCTION(focus);
JS_DECLARE_NATIVE_FUNCTION(get_selection);
diff --git a/Userland/Libraries/LibWeb/HTML/Window.idl b/Userland/Libraries/LibWeb/HTML/Window.idl
index 5dcef66cfc..daceb5001b 100644
--- a/Userland/Libraries/LibWeb/HTML/Window.idl
+++ b/Userland/Libraries/LibWeb/HTML/Window.idl
@@ -18,6 +18,7 @@ interface Window : EventTarget {
attribute DOMString name;
[PutForwards=href, LegacyUnforgeable] readonly attribute Location location;
readonly attribute History history;
+ undefined focus();
// other browsing contexts
[Replaceable] readonly attribute WindowProxy frames;