Skip to content

Commit

Permalink
Add preference to enable CDP in Firefox by default (SeleniumHQ#14091)
Browse files Browse the repository at this point in the history
Related to SeleniumHQ#11736
  • Loading branch information
pujagani authored and sandeepsuryaprasad committed Oct 29, 2024
1 parent d866903 commit febd025
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 10 deletions.
3 changes: 3 additions & 0 deletions dotnet/src/webdriver/Firefox/FirefoxOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ public FirefoxOptions()
this.AddKnownCapabilityName(FirefoxOptions.FirefoxLegacyProfileCapability, "Profile property");
this.AddKnownCapabilityName(FirefoxOptions.FirefoxLegacyBinaryCapability, "BrowserExecutableLocation property");
this.AddKnownCapabilityName(FirefoxOptions.FirefoxEnableDevToolsProtocolCapability, "EnableDevToolsProtocol property");
// 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/.
this.SetPreference("remote.active-protocols", 3);
}

/// <summary>
Expand Down
49 changes: 49 additions & 0 deletions java/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions java/src/org/openqa/selenium/firefox/FirefoxOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ 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/.
addPreference("remote.active-protocols", 3);
}

public FirefoxOptions(Capabilities source) {
Expand Down
3 changes: 3 additions & 0 deletions javascript/node/selenium-webdriver/firefox.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ class Options extends Capabilities {
constructor(other) {
super(other)
this.setBrowserName(Browser.FIREFOX)
// 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/.
this.setPreference('remote.active-protocols', 3)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ suite(
it('allows setting android activity', function () {
let options = new firefox.Options().enableMobile()
let firefoxOptions = options.firefoxOptions_()
assert.deepStrictEqual({ androidPackage: 'org.mozilla.firefox' }, firefoxOptions)
assert.deepStrictEqual(
{
androidPackage: 'org.mozilla.firefox',
prefs: { 'remote.active-protocols': 3 },
},
firefoxOptions,
)
})
})

Expand Down
3 changes: 3 additions & 0 deletions py/selenium/webdriver/firefox/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def __init__(self) -> None:
super().__init__()
self._binary_location = ""
self._preferences: dict = {}
# 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/.
self._preferences["remote.active-protocols"] = 3
self._profile = None
self.log = Log()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_set_proxy_isnt_in_moz_prefix(options):

caps = options.to_capabilities()
assert caps["proxy"]["proxyType"] == "manual"
assert caps.get("moz:firefoxOptions") is None
assert caps.get("moz:firefoxOptions") == {"prefs": {"remote.active-protocols": 3}}


def test_raises_exception_if_proxy_is_not_proxy_object(options):
Expand Down
4 changes: 2 additions & 2 deletions py/test/unit/selenium/webdriver/remote/new_session_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_works_as_context_manager(mocker):


@pytest.mark.parametrize("browser_name", ["firefox", "chrome", "ie"])
def test_accepts_options_to_remote_driver(mocker, browser_name):
def test_acepts_options_to_remote_driver(mocker, browser_name):
options = import_module(f"selenium.webdriver.{browser_name}.options")
mock = mocker.patch("selenium.webdriver.remote.webdriver.WebDriver.start_session")

Expand Down Expand Up @@ -103,7 +103,7 @@ def test_first_match_when_2_different_option_types():
"browserName": "firefox",
"acceptInsecureCerts": True,
"moz:debuggerAddress": True,
"moz:firefoxOptions": {"args": ["foo"]},
"moz:firefoxOptions": {"args": ["foo"], "prefs": {"remote.active-protocols": 3}},
},
],
}
Expand Down
3 changes: 3 additions & 0 deletions rb/lib/selenium/webdriver/firefox/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ def initialize(log_level: nil, **opts)

@options[:args] ||= []
@options[:prefs] ||= {}
# 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/.
@options[:prefs]['remote.active-protocols'] = 3
@options[:env] ||= {}
@options[:log] ||= {level: log_level} if log_level

Expand Down
7 changes: 5 additions & 2 deletions rb/spec/unit/selenium/webdriver/firefox/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module Firefox
def expect_request(body: nil, endpoint: nil)
body = (body || {capabilities: {alwaysMatch: {acceptInsecureCerts: true,
browserName: 'firefox',
'moz:firefoxOptions': {},
'moz:firefoxOptions': {prefs: {'remote.active-protocols' => 3}},
'moz:debuggerAddress': true}}}).to_json
endpoint ||= "#{service_manager.uri}/session"
stub_request(:post, endpoint).with(body: body).to_return(valid_response)
Expand Down Expand Up @@ -79,7 +79,10 @@ def expect_request(body: nil, endpoint: nil)
opts = {args: ['-f']}
expect_request(body: {capabilities: {alwaysMatch: {acceptInsecureCerts: true,
browserName: 'firefox',
'moz:firefoxOptions': opts,
'moz:firefoxOptions': {
args: ['-f'],
prefs: {'remote.active-protocols' => 3}
},
'moz:debuggerAddress': true}}})
expect { described_class.new(options: Options.new(**opts)) }.not_to raise_exception
end
Expand Down
8 changes: 4 additions & 4 deletions rb/spec/unit/selenium/webdriver/firefox/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ module Firefox
options.add_preference('intl.accepted_languages', 'en-US')

prefs = options.as_json['moz:firefoxOptions']['prefs']
expected = {'intl.accepted_languages' => 'en-US'}
expected = {'intl.accepted_languages' => 'en-US', 'remote.active-protocols' => 3}
expect(prefs).to eq(expected)
end
end
Expand Down Expand Up @@ -185,7 +185,7 @@ module Firefox
it 'returns empty options by default' do
expect(options.as_json).to eq('browserName' => 'firefox',
'acceptInsecureCerts' => true,
'moz:firefoxOptions' => {},
'moz:firefoxOptions' => {'prefs' => {'remote.active-protocols' => 3}},
'moz:debuggerAddress' => true)
end

Expand All @@ -195,7 +195,7 @@ module Firefox
'browserName' => 'firefox',
'foo:bar' => {'foo' => 'bar'},
'moz:debuggerAddress' => true,
'moz:firefoxOptions' => {})
'moz:firefoxOptions' => {'prefs' => {'remote.active-protocols' => 3}})
end

it 'converts to a json hash' do
Expand Down Expand Up @@ -240,7 +240,7 @@ module Firefox
'moz:debuggerAddress' => true,
key => {'args' => %w[foo bar],
'binary' => '/foo/bar',
'prefs' => {'foo' => 'bar'},
'prefs' => {'foo' => 'bar', 'remote.active-protocols' => 3},
'env' => {'FOO' => 'bar'},
'profile' => 'encoded_profile',
'log' => {'level' => 'debug'},
Expand Down

0 comments on commit febd025

Please sign in to comment.