From a982e0380e34e8f6e0240198a62f67e2a802d0da Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Wed, 12 Oct 2022 23:52:58 +0200 Subject: [PATCH] LibWeb: Implement navigator.webdriver This is defined via the NavigatorAutomationInformation interface mixin from the WebDriver spec: https://w3c.github.io/webdriver/#interface --- Userland/Libraries/LibWeb/HTML/Navigator.cpp | 14 ++++++++++++++ Userland/Libraries/LibWeb/HTML/Navigator.h | 2 ++ Userland/Libraries/LibWeb/HTML/Navigator.idl | 11 ++++++++--- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/Navigator.cpp b/Userland/Libraries/LibWeb/HTML/Navigator.cpp index e4af99045d..797566297f 100644 --- a/Userland/Libraries/LibWeb/HTML/Navigator.cpp +++ b/Userland/Libraries/LibWeb/HTML/Navigator.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2022, Andrew Kaster + * Copyright (c) 2022, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ @@ -8,6 +9,9 @@ #include #include #include +#include +#include +#include namespace Web::HTML { @@ -24,4 +28,14 @@ Navigator::Navigator(JS::Realm& realm) Navigator::~Navigator() = default; +// https://w3c.github.io/webdriver/#dfn-webdriver +bool Navigator::webdriver() const +{ + // Returns true if webdriver-active flag is set, false otherwise. + + // NOTE: The NavigatorAutomationInformation interface should not be exposed on WorkerNavigator. + auto const& window = verify_cast(HTML::current_global_object()); + return window.page()->is_webdriver_active(); +} + } diff --git a/Userland/Libraries/LibWeb/HTML/Navigator.h b/Userland/Libraries/LibWeb/HTML/Navigator.h index 3b54013b04..699bc6557a 100644 --- a/Userland/Libraries/LibWeb/HTML/Navigator.h +++ b/Userland/Libraries/LibWeb/HTML/Navigator.h @@ -39,6 +39,8 @@ public: // https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-pdfviewerenabled bool pdf_viewer_enabled() const { return false; } + bool webdriver() const; + virtual ~Navigator() override; private: diff --git a/Userland/Libraries/LibWeb/HTML/Navigator.idl b/Userland/Libraries/LibWeb/HTML/Navigator.idl index 7f0e43fbfb..7d81a2cf40 100644 --- a/Userland/Libraries/LibWeb/HTML/Navigator.idl +++ b/Userland/Libraries/LibWeb/HTML/Navigator.idl @@ -9,8 +9,8 @@ interface Navigator { // objects implementing this interface also implement the interfaces given below }; -// NOTE: As NavigatorContentUtils, NavigatorCookies, and NavigatorPlugins are not used in WorkerNavigator, -// we define them here. +// NOTE: As NavigatorContentUtils, NavigatorCookies, NavigatorPlugins, and NavigatorAutomationInformation +// are not used in WorkerNavigator, we define them here. // https://html.spec.whatwg.org/multipage/system-state.html#navigatorcontentutils interface mixin NavigatorContentUtils { @@ -31,6 +31,11 @@ interface mixin NavigatorPlugins { readonly attribute boolean pdfViewerEnabled; }; +// https://w3c.github.io/webdriver/#dom-navigatorautomationinformation +interface mixin NavigatorAutomationInformation { + readonly attribute boolean webdriver; +}; + Navigator includes NavigatorID; Navigator includes NavigatorLanguage; Navigator includes NavigatorOnLine; @@ -38,4 +43,4 @@ Navigator includes NavigatorContentUtils; Navigator includes NavigatorCookies; Navigator includes NavigatorPlugins; Navigator includes NavigatorConcurrentHardware; - +Navigator includes NavigatorAutomationInformation;