Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java][js][rb][py][dotnet] Remove firefox cdp #15200

Merged
merged 17 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 1 addition & 86 deletions dotnet/src/webdriver/Firefox/FirefoxDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
// under the License.
// </copyright>

using OpenQA.Selenium.DevTools;
using OpenQA.Selenium.Remote;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -71,11 +70,8 @@ namespace OpenQA.Selenium.Firefox
/// }
/// </code>
/// </example>
public class FirefoxDriver : WebDriver, IDevTools
public class FirefoxDriver : WebDriver
{
private const int FirefoxDevToolsProtocolVersion = 85;
private const string FirefoxDevToolsCapabilityName = "moz:debuggerAddress";

/// <summary>
/// Command for setting the command context of a Firefox driver.
/// </summary>
Expand Down Expand Up @@ -110,8 +106,6 @@ public class FirefoxDriver : WebDriver, IDevTools
{ GetFullPageScreenshotCommand, new HttpCommandInfo(HttpCommandInfo.GetCommand, "/session/{sessionId}/moz/screenshot/full") }
};

private DevToolsSession devToolsSession;

/// <summary>
/// Initializes a new instance of the <see cref="FirefoxDriver"/> class.
/// </summary>
Expand Down Expand Up @@ -244,14 +238,6 @@ public override IFileDetector FileDetector
set { }
}

/// <summary>
/// Gets a value indicating whether a DevTools session is active.
/// </summary>
public bool HasActiveDevToolsSession
{
get { return this.devToolsSession != null; }
}

/// <summary>
/// Sets the command context used when issuing commands to geckodriver.
/// </summary>
Expand Down Expand Up @@ -389,68 +375,6 @@ public Screenshot GetFullPageScreenshot()
return new Screenshot(base64);
}

/// <summary>
/// Creates a session to communicate with a browser using the Chromium Developer Tools debugging protocol.
/// </summary>
/// <returns>The active session to use to communicate with the Chromium Developer Tools debugging protocol.</returns>
[Obsolete("CDP support for Firefox is deprecated and will be removed in future versions. Please switch to WebDriver BiDi.")]
public DevToolsSession GetDevToolsSession()
{
return GetDevToolsSession(new DevToolsOptions() { ProtocolVersion = FirefoxDevToolsProtocolVersion });
}

/// <summary>
/// Creates a session to communicate with a browser using the Chromium Developer Tools debugging protocol.
/// </summary>
/// <param name="devToolsProtocolVersion">The version of the Chromium Developer Tools protocol to use. Defaults to autodetect the protocol version.</param>
/// <returns>The active session to use to communicate with the Chromium Developer Tools debugging protocol.</returns>
[Obsolete("Use GetDevToolsSession(DevToolsOptions options)")]
public DevToolsSession GetDevToolsSession(int devToolsProtocolVersion)
{
return GetDevToolsSession(new DevToolsOptions() { ProtocolVersion = devToolsProtocolVersion });
}

/// <summary>
/// Creates a session to communicate with a browser using a Developer Tools debugging protocol.
/// </summary>
/// <returns>The active session to use to communicate with the Developer Tools debugging protocol.</returns>
[Obsolete("CDP support for Firefox is deprecated and will be removed in future versions. Please switch to WebDriver BiDi.")]
public DevToolsSession GetDevToolsSession(DevToolsOptions options)
{
if (this.devToolsSession == null)
{
if (!this.Capabilities.HasCapability(FirefoxDevToolsCapabilityName))
{
throw new WebDriverException("Cannot find " + FirefoxDevToolsCapabilityName + " capability for driver");
}

string debuggerAddress = this.Capabilities.GetCapability(FirefoxDevToolsCapabilityName).ToString();
try
{
DevToolsSession session = new DevToolsSession(debuggerAddress, options);
Task.Run(async () => await session.StartSession()).GetAwaiter().GetResult();
this.devToolsSession = session;
}
catch (Exception e)
{
throw new WebDriverException("Unexpected error creating WebSocket DevTools session.", e);
}
}

return this.devToolsSession;
}

/// <summary>
/// Closes a DevTools session.
/// </summary>
public void CloseDevToolsSession()
{
if (this.devToolsSession != null)
{
Task.Run(async () => await this.devToolsSession.StopSession(true)).GetAwaiter().GetResult();
}
}

/// <summary>
/// In derived classes, the <see cref="PrepareEnvironment"/> method prepares the environment for test execution.
/// </summary>
Expand All @@ -467,15 +391,6 @@ protected virtual void PrepareEnvironment()
/// disposing the object; otherwise <see langword="false"/>.</param>
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (this.devToolsSession != null)
{
this.devToolsSession.Dispose();
this.devToolsSession = null;
}
}

base.Dispose(disposing);
}

Expand Down
106 changes: 2 additions & 104 deletions java/src/org/openqa/selenium/firefox/FirefoxDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.nio.file.Path;
import java.util.Map;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand All @@ -33,20 +32,11 @@
import org.openqa.selenium.ImmutableCapabilities;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.PersistentCapabilities;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.bidi.BiDi;
import org.openqa.selenium.bidi.BiDiException;
import org.openqa.selenium.bidi.HasBiDi;
import org.openqa.selenium.devtools.CdpEndpointFinder;
import org.openqa.selenium.devtools.CdpInfo;
import org.openqa.selenium.devtools.CdpVersionFinder;
import org.openqa.selenium.devtools.Connection;
import org.openqa.selenium.devtools.DevTools;
import org.openqa.selenium.devtools.DevToolsException;
import org.openqa.selenium.devtools.HasDevTools;
import org.openqa.selenium.devtools.noop.NoOpCdpInfo;
import org.openqa.selenium.html5.LocalStorage;
import org.openqa.selenium.html5.SessionStorage;
import org.openqa.selenium.html5.WebStorage;
Expand Down Expand Up @@ -78,18 +68,15 @@
* </pre>
*/
public class FirefoxDriver extends RemoteWebDriver
implements WebStorage, HasExtensions, HasFullPageScreenshot, HasContext, HasDevTools, HasBiDi {
implements WebStorage, HasExtensions, HasFullPageScreenshot, HasContext, HasBiDi {

private static final Logger LOG = Logger.getLogger(FirefoxDriver.class.getName());
private final Capabilities capabilities;
private final RemoteWebStorage webStorage;
private final HasExtensions extensions;
private final HasFullPageScreenshot fullPageScreenshot;
private final HasContext context;
private final Optional<URI> cdpUri;
private final Optional<URI> biDiUri;
private Connection connection;
private DevTools devTools;
private final Optional<BiDi> biDi;

/**
Expand Down Expand Up @@ -160,41 +147,6 @@ private FirefoxDriver(
context = new AddHasContext().getImplementation(getCapabilities(), getExecuteMethod());

Capabilities capabilities = super.getCapabilities();
HttpClient.Factory factory = HttpClient.Factory.createDefault();

Optional<URI> reportedUri =
CdpEndpointFinder.getReportedUri("moz:debuggerAddress", capabilities);

if (reportedUri.isPresent() && !capabilities.is("webSocketUrl")) {
LOG.warning(
"CDP support for Firefox is deprecated and will be removed in future versions. "
+ "Please switch to WebDriver BiDi.");
}

Optional<HttpClient> client =
reportedUri.map(uri -> CdpEndpointFinder.getHttpClient(factory, uri));
Optional<URI> cdpUri;

try {
cdpUri = client.flatMap(CdpEndpointFinder::getCdpEndPoint);
} catch (Exception e) {
try {
client.ifPresent(HttpClient::close);
} catch (Exception ex) {
e.addSuppressed(ex);
}
throw e;
}

try {
client.ifPresent(HttpClient::close);
} catch (Exception e) {
LOG.log(
Level.FINE,
"failed to close the http client used to check the reported CDP endpoint: "
+ reportedUri.get(),
e);
}

Optional<String> webSocketUrl =
Optional.ofNullable((String) capabilities.getCapability("webSocketUrl"));
Expand All @@ -212,16 +164,7 @@ private FirefoxDriver(

this.biDi = createBiDi(biDiUri);

this.cdpUri = cdpUri;
this.capabilities =
cdpUri
.map(
uri ->
new ImmutableCapabilities(
new PersistentCapabilities(capabilities)
.setCapability("se:cdp", uri.toString())
.setCapability("se:cdpVersion", "85.0")))
.orElse(new ImmutableCapabilities(capabilities));
this.capabilities = new ImmutableCapabilities(capabilities);
}

@Beta
Expand Down Expand Up @@ -315,51 +258,6 @@ public void setContext(FirefoxCommandContext commandContext) {
context.setContext(commandContext);
}

/**
* @deprecated Use W3C-compliant BiDi protocol. Use {{@link #maybeGetBiDi()}}
*/
@Deprecated
@Override
public Optional<DevTools> maybeGetDevTools() {
if (devTools != null) {
return Optional.of(devTools);
}

if (!cdpUri.isPresent()) {
return Optional.empty();
}

URI wsUri =
cdpUri.orElseThrow(
() ->
new DevToolsException(
"This version of Firefox or geckodriver does not support CDP"));
HttpClient.Factory clientFactory = HttpClient.Factory.createDefault();

ClientConfig wsConfig = ClientConfig.defaultConfig().baseUri(wsUri);
HttpClient wsClient = clientFactory.createClient(wsConfig);

connection = new Connection(wsClient, wsUri.toString());
CdpInfo cdpInfo = new CdpVersionFinder().match("85.0").orElseGet(NoOpCdpInfo::new);
devTools = new DevTools(cdpInfo::getDomains, connection);

return Optional.of(devTools);
}

/**
* @deprecated Use W3C-compliant BiDi protocol. Use {{@link #getBiDi()}}
*/
@Deprecated
@Override
public DevTools getDevTools() {
if (!cdpUri.isPresent()) {
throw new DevToolsException("This version of Firefox or geckodriver does not support CDP");
}

return maybeGetDevTools()
.orElseThrow(() -> new DevToolsException("Unable to initialize CDP connection"));
}

private Optional<BiDi> createBiDi(Optional<URI> biDiUri) {
if (biDiUri.isEmpty()) {
return Optional.empty();
Expand Down
1 change: 0 additions & 1 deletion java/src/org/openqa/selenium/firefox/FirefoxOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public class FirefoxOptions extends AbstractDriverOptions<FirefoxOptions> {
public FirefoxOptions() {
setCapability(CapabilityType.BROWSER_NAME, FIREFOX.browserName());
setAcceptInsecureCerts(true);
setCapability("moz:debuggerAddress", true);
// Firefox 129 onwards the CDP protocol will not be enabled by default. Setting this preference
// will enable it.
// https://fxdx.dev/deprecating-cdp-support-in-firefox-embracing-the-future-with-webdriver-bidi/.
Expand Down
1 change: 0 additions & 1 deletion java/test/org/openqa/selenium/devtools/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ java_selenium_test_suite(
srcs = glob(["*Test.java"]),
browsers = [
"chrome",
"firefox",
"edge",
],
tags = [
Expand Down
4 changes: 0 additions & 4 deletions java/test/org/openqa/selenium/devtools/CdpFacadeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
import org.openqa.selenium.remote.http.Contents;
import org.openqa.selenium.remote.http.HttpResponse;
import org.openqa.selenium.remote.http.Route;
import org.openqa.selenium.testing.NotYetImplemented;
import org.openqa.selenium.testing.drivers.Browser;

class CdpFacadeTest extends DevToolsTestBase {

Expand All @@ -61,7 +59,6 @@ public static void stopServer() {
}

@Test
@NotYetImplemented(value = Browser.FIREFOX, reason = "Network interception not yet supported")
public void networkInterceptorAndAuthHandlersDoNotFight() {
assumeThat(driver).isInstanceOf(HasAuthentication.class);

Expand Down Expand Up @@ -95,7 +92,6 @@ public void networkInterceptorAndAuthHandlersDoNotFight() {
}

@Test
@NotYetImplemented(value = Browser.FIREFOX, reason = "Network interception not yet supported")
public void canAuthenticate() {
assumeThat(driver).isInstanceOf(HasAuthentication.class);

Expand Down
10 changes: 2 additions & 8 deletions javascript/node/selenium-webdriver/lib/webdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1244,9 +1244,7 @@ class WebDriver {
const caps = await this.getCapabilities()

if (caps['map_'].get('browserName') === 'firefox') {
console.warn(
'CDP support for Firefox is deprecated and will be removed in future versions. Please switch to WebDriver BiDi.',
)
throw new Error('CDP support for Firefox is removed. Please switch to WebDriver BiDi.')
}

if (process.env.SELENIUM_REMOTE_URL) {
Expand All @@ -1255,11 +1253,7 @@ class WebDriver {
debuggerUrl = `ws://${host}/session/${sessionId}/se/cdp`
} else {
const seCdp = caps['map_'].get('se:cdp')
const vendorInfo =
caps['map_'].get('goog:chromeOptions') ||
caps['map_'].get('ms:edgeOptions') ||
caps['map_'].get('moz:debuggerAddress') ||
new Map()
const vendorInfo = caps['map_'].get('goog:chromeOptions') || caps['map_'].get('ms:edgeOptions') || new Map()
debuggerUrl = seCdp || vendorInfo['debuggerAddress'] || vendorInfo
}
this._wsUrl = await this.getWsUrl(debuggerUrl, target, caps)
Expand Down
Loading
Loading