diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp
index bca88a83b97..ef95665e5b2 100644
--- a/Userland/Libraries/LibWeb/HTML/Window.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Window.cpp
@@ -118,13 +118,6 @@ void Window::visit_edges(JS::Cell::Visitor& visitor)
Window::~Window() = default;
-CSS::Screen& Window::screen()
-{
- if (!m_screen)
- m_screen = heap().allocate(realm(), *this).release_allocated_value_but_fixme_should_propagate_errors();
- return *m_screen;
-}
-
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#normalizing-the-feature-name
static StringView normalize_feature_name(StringView name)
{
@@ -1037,7 +1030,6 @@ WebIDL::ExceptionOr Window::initialize_web_interfaces(Badge> Window::match_media(S
return media_query_list;
}
+// https://w3c.github.io/csswg-drafts/cssom-view/#dom-window-screen
+WebIDL::ExceptionOr> Window::screen()
+{
+ // The screen attribute must return the Screen object associated with the Window object.
+ if (!m_screen)
+ m_screen = MUST_OR_THROW_OOM(heap().allocate(realm(), *this));
+ return JS::NonnullGCPtr { *m_screen };
+}
+
// https://w3c.github.io/hr-time/#dom-windoworworkerglobalscope-performance
WebIDL::ExceptionOr> Window::performance()
{
@@ -1523,17 +1524,6 @@ size_t Window::document_tree_child_browsing_context_count() const
return this_browsing_context->document_tree_child_browsing_context_count();
}
-JS_DEFINE_NATIVE_FUNCTION(Window::screen_getter)
-{
- auto* impl = TRY(impl_from(vm));
- return &impl->screen();
-}
-
-JS_DEFINE_NATIVE_FUNCTION(Window::screen_setter)
-{
- REPLACEABLE_PROPERTY_SETTER(Window, screen);
-}
-
JS_DEFINE_NATIVE_FUNCTION(Window::location_setter)
{
auto* impl = TRY(impl_from(vm));
diff --git a/Userland/Libraries/LibWeb/HTML/Window.h b/Userland/Libraries/LibWeb/HTML/Window.h
index 35ca5b42efe..ab0dacff048 100644
--- a/Userland/Libraries/LibWeb/HTML/Window.h
+++ b/Userland/Libraries/LibWeb/HTML/Window.h
@@ -96,8 +96,6 @@ public:
void deallocate_timer_id(Badge, i32);
- CSS::Screen& screen();
-
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);
@@ -165,6 +163,7 @@ public:
Variant, JS::Value> event() const;
WebIDL::ExceptionOr> match_media(String const& query);
+ WebIDL::ExceptionOr> screen();
WebIDL::ExceptionOr> performance();
@@ -232,9 +231,6 @@ public:
private:
JS_DECLARE_NATIVE_FUNCTION(location_setter);
- JS_DECLARE_NATIVE_FUNCTION(screen_getter);
- JS_DECLARE_NATIVE_FUNCTION(screen_setter);
-
JS_DECLARE_NATIVE_FUNCTION(inner_width_getter);
JS_DECLARE_NATIVE_FUNCTION(inner_height_getter);
diff --git a/Userland/Libraries/LibWeb/HTML/Window.idl b/Userland/Libraries/LibWeb/HTML/Window.idl
index 18a1c0920a4..ef02814c526 100644
--- a/Userland/Libraries/LibWeb/HTML/Window.idl
+++ b/Userland/Libraries/LibWeb/HTML/Window.idl
@@ -1,5 +1,6 @@
#import
#import
+#import
#import
#import
#import
@@ -45,6 +46,7 @@ interface Window : EventTarget {
// https://w3c.github.io/csswg-drafts/cssom-view/#extensions-to-the-window-interface
[NewObject] MediaQueryList matchMedia(CSSOMString query);
+ [SameObject, Replaceable] readonly attribute Screen screen;
// FIXME: Everything from here on should be shared through WindowOrWorkerGlobalScope
// https://w3c.github.io/hr-time/#the-performance-attribute