From 6a200d5284a823daae93c1b73b95d3a1df293c62 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Mon, 17 Jun 2024 09:44:52 +0200 Subject: [PATCH] No Issue - Add navigator.webdriver attribute. This patch adds an enumerable, configurable, readonly attribute "webdriver" to the Navigator object. The attribute is always false because we do not support WebDriver or scripted automation. The navigator.webdriver attribute is meant as an indication to web authors that a document is visited by WebDriver. It is important to stress that it is not meant as a way to detect that a website is being visited by a browser automation tool or bot, but as a tool for web documents to take alternate code paths. On the off-chance exposing navigator.webdriver turns out to be catastrophic, we put it behind a new preference dom.webdriver.enabled that controls its exposure. --- dom/base/Navigator.cpp | 8 ++++++++ dom/base/Navigator.h | 2 ++ dom/webidl/Navigator.webidl | 9 +++++++++ modules/libpref/init/all.js | 3 +++ 4 files changed, 22 insertions(+) diff --git a/dom/base/Navigator.cpp b/dom/base/Navigator.cpp index 0f7f2b756e..026ae15836 100644 --- a/dom/base/Navigator.cpp +++ b/dom/base/Navigator.cpp @@ -1532,6 +1532,14 @@ Navigator::Clipboard() return mClipboard; } +/* static */ +bool +Navigator::Webdriver() +{ + // We don't support Selenium or marionette, so this is always false. + return false; +} + #ifdef MOZ_EME static nsCString ToCString(const nsString& aString) diff --git a/dom/base/Navigator.h b/dom/base/Navigator.h index 10f9573ee9..d674f5cedc 100644 --- a/dom/base/Navigator.h +++ b/dom/base/Navigator.h @@ -219,6 +219,8 @@ public: dom::Clipboard* Clipboard(); + static bool Webdriver(); + void GetLanguages(nsTArray& aLanguages); bool MozE10sEnabled(); diff --git a/dom/webidl/Navigator.webidl b/dom/webidl/Navigator.webidl index f2212de392..4541210a08 100644 --- a/dom/webidl/Navigator.webidl +++ b/dom/webidl/Navigator.webidl @@ -12,6 +12,7 @@ * https://dvcs.w3.org/hg/gamepad/raw-file/default/gamepad.html#navigator-interface-extension * http://www.w3.org/TR/beacon/#sec-beacon-method * https://html.spec.whatwg.org/#navigatorconcurrenthardware + * https://w3c.github.io/webdriver/webdriver-spec.html#interface * * © Copyright 2004-2020 Apple Computer, Inc., Mozilla Foundation, * Opera Software ASA and Moonchild Productions. You are granted a license to use, @@ -31,6 +32,7 @@ Navigator implements NavigatorStorageUtils; Navigator implements NavigatorConcurrentHardware; Navigator implements NavigatorStorage; Navigator implements NavigatorGlobalPrivacyControl; +Navigator implements NavigatorAutomationInformation; [NoInterfaceObject, Exposed=(Window,Worker)] interface NavigatorID { @@ -334,3 +336,10 @@ partial interface Navigator { [Pref="dom.events.asyncClipboard", SecureContext, SameObject] readonly attribute Clipboard clipboard; }; + +// https://w3c.github.io/webdriver/webdriver-spec.html#interface +[NoInterfaceObject, Exposed=Window] +interface NavigatorAutomationInformation { + [Pref="dom.webdriver.enabled"] + readonly attribute boolean webdriver; +}; diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 56c82aa1d9..9d11726d47 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -5259,6 +5259,9 @@ pref("media.seekToNextFrame.enabled", true); // return the maximum number of cores that navigator.hardwareConcurrency returns pref("dom.maxHardwareConcurrency", 16); +// Exposes the navigator.webdriver attribute. +pref("dom.webdriver.enabled", true); + // Shutdown the async osfile worker if it's no longer needed. pref("osfile.reset_worker_delay", 30000);