LibWeb: Implement navigator.webdriver

This is defined via the NavigatorAutomationInformation interface mixin
from the WebDriver spec: https://w3c.github.io/webdriver/#interface
This commit is contained in:
Linus Groh 2022-10-12 23:52:58 +02:00 committed by Andreas Kling
parent 68006f3e16
commit a982e0380e
Notes: sideshowbarker 2024-07-17 07:25:39 +09:00
3 changed files with 24 additions and 3 deletions

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2022, Andrew Kaster <akaster@serenityos.org>
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -8,6 +9,9 @@
#include <LibJS/Runtime/Realm.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/HTML/Navigator.h>
#include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/Page/Page.h>
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::Window>(HTML::current_global_object());
return window.page()->is_webdriver_active();
}
}

View file

@ -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:

View file

@ -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;