2424import java .nio .file .Path ;
2525import java .util .Map ;
2626import java .util .Optional ;
27- import java .util .logging .Level ;
2827import java .util .logging .Logger ;
2928import java .util .stream .Collectors ;
3029import java .util .stream .Stream ;
3332import org .openqa .selenium .ImmutableCapabilities ;
3433import org .openqa .selenium .MutableCapabilities ;
3534import org .openqa .selenium .OutputType ;
36- import org .openqa .selenium .PersistentCapabilities ;
3735import org .openqa .selenium .Proxy ;
3836import org .openqa .selenium .WebDriverException ;
3937import org .openqa .selenium .bidi .BiDi ;
4038import org .openqa .selenium .bidi .BiDiException ;
4139import org .openqa .selenium .bidi .HasBiDi ;
42- import org .openqa .selenium .devtools .CdpEndpointFinder ;
43- import org .openqa .selenium .devtools .CdpInfo ;
44- import org .openqa .selenium .devtools .CdpVersionFinder ;
45- import org .openqa .selenium .devtools .Connection ;
46- import org .openqa .selenium .devtools .DevTools ;
47- import org .openqa .selenium .devtools .DevToolsException ;
48- import org .openqa .selenium .devtools .HasDevTools ;
49- import org .openqa .selenium .devtools .noop .NoOpCdpInfo ;
5040import org .openqa .selenium .html5 .LocalStorage ;
5141import org .openqa .selenium .html5 .SessionStorage ;
5242import org .openqa .selenium .html5 .WebStorage ;
7868 * </pre>
7969 */
8070public class FirefoxDriver extends RemoteWebDriver
81- implements WebStorage , HasExtensions , HasFullPageScreenshot , HasContext , HasDevTools , HasBiDi {
71+ implements WebStorage , HasExtensions , HasFullPageScreenshot , HasContext , HasBiDi {
8272
8373 private static final Logger LOG = Logger .getLogger (FirefoxDriver .class .getName ());
8474 private final Capabilities capabilities ;
8575 private final RemoteWebStorage webStorage ;
8676 private final HasExtensions extensions ;
8777 private final HasFullPageScreenshot fullPageScreenshot ;
8878 private final HasContext context ;
89- private final Optional <URI > cdpUri ;
9079 private final Optional <URI > biDiUri ;
91- private Connection connection ;
92- private DevTools devTools ;
9380 private final Optional <BiDi > biDi ;
9481
9582 /**
@@ -160,41 +147,6 @@ private FirefoxDriver(
160147 context = new AddHasContext ().getImplementation (getCapabilities (), getExecuteMethod ());
161148
162149 Capabilities capabilities = super .getCapabilities ();
163- HttpClient .Factory factory = HttpClient .Factory .createDefault ();
164-
165- Optional <URI > reportedUri =
166- CdpEndpointFinder .getReportedUri ("moz:debuggerAddress" , capabilities );
167-
168- if (reportedUri .isPresent () && !capabilities .is ("webSocketUrl" )) {
169- LOG .warning (
170- "CDP support for Firefox is deprecated and will be removed in future versions. "
171- + "Please switch to WebDriver BiDi." );
172- }
173-
174- Optional <HttpClient > client =
175- reportedUri .map (uri -> CdpEndpointFinder .getHttpClient (factory , uri ));
176- Optional <URI > cdpUri ;
177-
178- try {
179- cdpUri = client .flatMap (CdpEndpointFinder ::getCdpEndPoint );
180- } catch (Exception e ) {
181- try {
182- client .ifPresent (HttpClient ::close );
183- } catch (Exception ex ) {
184- e .addSuppressed (ex );
185- }
186- throw e ;
187- }
188-
189- try {
190- client .ifPresent (HttpClient ::close );
191- } catch (Exception e ) {
192- LOG .log (
193- Level .FINE ,
194- "failed to close the http client used to check the reported CDP endpoint: "
195- + reportedUri .get (),
196- e );
197- }
198150
199151 Optional <String > webSocketUrl =
200152 Optional .ofNullable ((String ) capabilities .getCapability ("webSocketUrl" ));
@@ -212,16 +164,7 @@ private FirefoxDriver(
212164
213165 this .biDi = createBiDi (biDiUri );
214166
215- this .cdpUri = cdpUri ;
216- this .capabilities =
217- cdpUri
218- .map (
219- uri ->
220- new ImmutableCapabilities (
221- new PersistentCapabilities (capabilities )
222- .setCapability ("se:cdp" , uri .toString ())
223- .setCapability ("se:cdpVersion" , "85.0" )))
224- .orElse (new ImmutableCapabilities (capabilities ));
167+ this .capabilities = new ImmutableCapabilities (capabilities );
225168 }
226169
227170 @ Beta
@@ -315,51 +258,6 @@ public void setContext(FirefoxCommandContext commandContext) {
315258 context .setContext (commandContext );
316259 }
317260
318- /**
319- * @deprecated Use W3C-compliant BiDi protocol. Use {{@link #maybeGetBiDi()}}
320- */
321- @ Deprecated
322- @ Override
323- public Optional <DevTools > maybeGetDevTools () {
324- if (devTools != null ) {
325- return Optional .of (devTools );
326- }
327-
328- if (!cdpUri .isPresent ()) {
329- return Optional .empty ();
330- }
331-
332- URI wsUri =
333- cdpUri .orElseThrow (
334- () ->
335- new DevToolsException (
336- "This version of Firefox or geckodriver does not support CDP" ));
337- HttpClient .Factory clientFactory = HttpClient .Factory .createDefault ();
338-
339- ClientConfig wsConfig = ClientConfig .defaultConfig ().baseUri (wsUri );
340- HttpClient wsClient = clientFactory .createClient (wsConfig );
341-
342- connection = new Connection (wsClient , wsUri .toString ());
343- CdpInfo cdpInfo = new CdpVersionFinder ().match ("85.0" ).orElseGet (NoOpCdpInfo ::new );
344- devTools = new DevTools (cdpInfo ::getDomains , connection );
345-
346- return Optional .of (devTools );
347- }
348-
349- /**
350- * @deprecated Use W3C-compliant BiDi protocol. Use {{@link #getBiDi()}}
351- */
352- @ Deprecated
353- @ Override
354- public DevTools getDevTools () {
355- if (!cdpUri .isPresent ()) {
356- throw new DevToolsException ("This version of Firefox or geckodriver does not support CDP" );
357- }
358-
359- return maybeGetDevTools ()
360- .orElseThrow (() -> new DevToolsException ("Unable to initialize CDP connection" ));
361- }
362-
363261 private Optional <BiDi > createBiDi (Optional <URI > biDiUri ) {
364262 if (biDiUri .isEmpty ()) {
365263 return Optional .empty ();
0 commit comments