Skip to content

Commit 5da0995

Browse files
authored
feat: implement webdriver BiDi for Firefox versions 135 and greater (#30870)
* feat: implement BiDi automation client base (without full extension cutover). [run ci] * chore: implement suggestions from code review. [run ci] * update error text to be in line with documentation * address comments from code review * address comments from code review * make bidi, cdp, and both active protocols object enumerations to make the code easier to read * address additional comments from code review * fix errors from refactor * update firefox warning
1 parent 0177508 commit 5da0995

24 files changed

+1468
-230
lines changed

.circleci/cache-version.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Bump this version to force CI to re-create the cache from scratch.
22

3-
2-10-25
3+
2-12-25

.circleci/workflows.yml

+41-5
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ mainBuildFilters: &mainBuildFilters
3636
only:
3737
- develop
3838
- /^release\/\d+\.\d+\.\d+$/
39-
- chore/update_wdio_deps
39+
- feat/implement_bidi
4040
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
4141
- 'update-v8-snapshot-cache-on-develop'
4242
- 'ryanm/chore/add_internal_studio'
@@ -50,7 +50,7 @@ macWorkflowFilters: &darwin-workflow-filters
5050
- equal: [ develop, << pipeline.git.branch >> ]
5151
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
5252
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
53-
- equal: [ 'ryanm/chore/add_internal_studio', << pipeline.git.branch >> ]
53+
- equal: [ 'feat/implement_bidi', << pipeline.git.branch >> ]
5454
- matches:
5555
pattern: /^release\/\d+\.\d+\.\d+$/
5656
value: << pipeline.git.branch >>
@@ -61,7 +61,7 @@ linuxArm64WorkflowFilters: &linux-arm64-workflow-filters
6161
- equal: [ develop, << pipeline.git.branch >> ]
6262
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
6363
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
64-
- equal: [ 'ryanm/chore/add_internal_studio', << pipeline.git.branch >> ]
64+
- equal: [ 'feat/implement_bidi', << pipeline.git.branch >> ]
6565
- matches:
6666
pattern: /^release\/\d+\.\d+\.\d+$/
6767
value: << pipeline.git.branch >>
@@ -84,7 +84,7 @@ windowsWorkflowFilters: &windows-workflow-filters
8484
- equal: [ develop, << pipeline.git.branch >> ]
8585
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
8686
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
87-
- equal: [ 'ryanm/chore/add_internal_studio', << pipeline.git.branch >> ]
87+
- equal: [ 'feat/implement_bidi', << pipeline.git.branch >> ]
8888
- matches:
8989
pattern: /^release\/\d+\.\d+\.\d+$/
9090
value: << pipeline.git.branch >>
@@ -160,7 +160,7 @@ commands:
160160
name: Set environment variable to determine whether or not to persist artifacts
161161
command: |
162162
echo "Setting SHOULD_PERSIST_ARTIFACTS variable"
163-
echo 'if ! [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "ryanm/chore/add_internal_studio" ]]; then
163+
echo 'if ! [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "feat/implement_bidi" ]]; then
164164
export SHOULD_PERSIST_ARTIFACTS=true
165165
fi' >> "$BASH_ENV"
166166
# You must run `setup_should_persist_artifacts` command and be using bash before running this command
@@ -651,10 +651,19 @@ commands:
651651
description: chrome channel to install
652652
type: string
653653
default: 'stable'
654+
firefox-version:
655+
description: firefox version to install
656+
type: string
657+
default: *firefox-stable-version
654658
inject-document-domain:
655659
description: run subset of tests with injectDocumentDomain config enabled
656660
type: boolean
657661
default: false
662+
is-firefox-cdp:
663+
description: whether or not the group should be associated to the firefox CDP
664+
run or not. This is determined by the browser version.
665+
type: boolean
666+
default: false
658667

659668
steps:
660669
- restore_cached_workspace
@@ -678,6 +687,7 @@ commands:
678687
steps:
679688
- install-browsers:
680689
install-firefox: true
690+
firefox-version: << parameters.firefox-version >>
681691
- when:
682692
condition:
683693
equal: [ webkit, << parameters.browser >> ]
@@ -695,6 +705,9 @@ commands:
695705
if << parameters.inject-document-domain >> ; then
696706
YARN_CMD="cypress:run:inject-document-domain"
697707
PARALLEL="--parallel --group 5x-driver-inject-document-domain-<<parameters.browser>>"
708+
elif << parameters.is-firefox-cdp >> ; then
709+
YARN_CMD="cypress:run"
710+
PARALLEL="--parallel --group 5x-driver-cdp-<<parameters.browser>>"
698711
else
699712
YARN_CMD="cypress:run"
700713
PARALLEL="--parallel --group 5x-driver-<<parameters.browser>>"
@@ -2182,6 +2195,18 @@ jobs:
21822195
- run-driver-integration-tests:
21832196
browser: firefox
21842197

2198+
# Runs the driver tests using firefox 134, which does NOT use WebDriver BiDi
2199+
# This is to test and make sure there aren't regressions with the old CDP driver
2200+
driver-integration-tests-firefox-cdp:
2201+
<<: *defaults
2202+
resource_class: medium+
2203+
parallelism: 5
2204+
steps:
2205+
- run-driver-integration-tests:
2206+
browser: firefox
2207+
firefox-version: "134.0.2"
2208+
is-firefox-cdp: true
2209+
21852210
driver-integration-tests-electron:
21862211
<<: *defaults
21872212
parallelism: 5
@@ -2990,6 +3015,7 @@ linux-x64-workflow: &linux-x64-workflow
29903015
- run-webpack-dev-server-integration-tests
29913016
- run-vite-dev-server-integration-tests
29923017
- driver-integration-tests-firefox
3018+
- driver-integration-tests-firefox-cdp
29933019
- driver-integration-tests-chrome
29943020
- driver-integration-tests-chrome-inject-document-domain
29953021
- driver-integration-tests-chrome-beta-inject-document-domain
@@ -3065,6 +3091,10 @@ linux-x64-workflow: &linux-x64-workflow
30653091
context: test-runner:cypress-record-key
30663092
requires:
30673093
- build
3094+
- driver-integration-tests-firefox-cdp:
3095+
context: test-runner:cypress-record-key
3096+
requires:
3097+
- build
30683098
- driver-integration-tests-electron:
30693099
context: test-runner:cypress-record-key
30703100
requires:
@@ -3207,6 +3237,7 @@ linux-x64-workflow: &linux-x64-workflow
32073237
- linux-lint
32083238
- percy-finalize
32093239
- driver-integration-tests-firefox
3240+
- driver-integration-tests-firefox-cdp
32103241
- driver-integration-tests-chrome
32113242
- driver-integration-tests-chrome-beta
32123243
- driver-integration-tests-chrome-inject-document-domain
@@ -3461,6 +3492,10 @@ linux-x64-contributor-workflow: &linux-x64-contributor-workflow
34613492
context: test-runner:cypress-record-key
34623493
requires:
34633494
- contributor-pr
3495+
- driver-integration-tests-firefox-cdp:
3496+
context: test-runner:cypress-record-key
3497+
requires:
3498+
- contributor-pr
34643499
- driver-integration-tests-electron:
34653500
context: test-runner:cypress-record-key
34663501
requires:
@@ -3602,6 +3637,7 @@ linux-x64-contributor-workflow: &linux-x64-contributor-workflow
36023637
- linux-lint
36033638
- percy-finalize
36043639
- driver-integration-tests-firefox
3640+
- driver-integration-tests-firefox-cdp
36053641
- driver-integration-tests-chrome
36063642
- driver-integration-tests-chrome-beta
36073643
- driver-integration-tests-electron

cli/CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
<!-- See the ../guides/writing-the-cypress-changelog.md for details on writing the changelog. -->
2-
## 14.0.4
2+
## 14.1.0
33

44
_Released 2/25/2025 (PENDING)_
55

6+
**Features:**
7+
8+
- Firefox versions 135 and up are now automated with [WebDriver BiDi](https://www.w3.org/TR/webdriver-bidi/) instead of [Chrome Devtools Protocol](https://chromedevtools.github.io/devtools-protocol/). Addresses [#30220](https://github.com/cypress-io/cypress/issues/30220).
9+
610
**Misc:**
711

812
- Viewport width, height, and scale now display in a badge above the application under test. The dropdown describing how to set viewport height and width has been removed from the UI. Additionally, component tests now show a notice about URL navigation being disabled in component tests. Addresses [#30999](https://github.com/cypress-io/cypress/issues/30999). Addressed in [#31119](https://github.com/cypress-io/cypress/pull/31119).

packages/driver/cypress/e2e/e2e/service-worker.cy.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,9 @@ describe('service workers', { defaultCommandTimeout: 1000, pageLoadTimeout: 1000
711711
})
712712

713713
cy.visit('fixtures/service-worker.html')
714-
cy.get('#output').should('have.text', 'done')
714+
cy.get('#output', {
715+
// request takes a little longer with WebDriver BiDi to return (Firefox 135+ only)
716+
timeout: 8000,
717+
}).should('have.text', 'done')
715718
})
716719
})

packages/errors/src/errors.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,9 @@ export const AllCypressErrors = {
11801180
CDP_RETRYING_CONNECTION: (attempt: string | number, browserName: string, connectRetryThreshold: number) => {
11811181
return errTemplate`Still waiting to connect to ${fmt.off(_.capitalize(browserName))}, retrying in 1 second ${fmt.meta(`(attempt ${attempt}/${connectRetryThreshold})`)}`
11821182
},
1183+
CDP_FIREFOX_DEPRECATED: () => {
1184+
return errTemplate`Since Firefox 129, Chrome DevTools Protocol (CDP) has been deprecated in Firefox. In Firefox 135 and above, Cypress defaults to automating the Firefox browser with WebDriver BiDi. Cypress will no longer support CDP within Firefox in the future and is planned for removal in Cypress 15.`
1185+
},
11831186
BROWSER_PROCESS_CLOSED_UNEXPECTEDLY: (browserName: string) => {
11841187
return errTemplate`\
11851188
We detected that the ${fmt.highlight(browserName)} browser process closed unexpectedly.

packages/errors/test/unit/visualSnapshotErrors_spec.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,11 @@ describe('visual error templates', () => {
11121112
default: [1, 'chrome', 62],
11131113
}
11141114
},
1115+
CDP_FIREFOX_DEPRECATED: () => {
1116+
return {
1117+
default: [],
1118+
}
1119+
},
11151120
BROWSER_PROCESS_CLOSED_UNEXPECTEDLY: () => {
11161121
return {
11171122
default: ['chrome'],

packages/extension/app/v2/background.js

+25-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ const checkIfFirefox = async () => {
3131
return name === 'Firefox'
3232
}
3333

34+
// this check only applies to firefox versioning!
35+
const isBiDiEnabled = async (config) => {
36+
if (!browser || !get(browser, 'runtime.getBrowserInfo') || config.IS_CDP_FORCED_FOR_FIREFOX) {
37+
return false
38+
}
39+
40+
const { version } = await browser.runtime.getBrowserInfo()
41+
42+
if (version) {
43+
const [majorVersion] = version.split('.').map(Number)
44+
45+
return majorVersion >= 135
46+
}
47+
48+
return false
49+
}
50+
3451
const connect = function (host, path, extraOpts) {
3552
const listenToCookieChanges = once(() => {
3653
return browser.cookies.onChanged.addListener((info) => {
@@ -147,10 +164,16 @@ const connect = function (host, path, extraOpts) {
147164
const isFirefox = await checkIfFirefox()
148165

149166
listenToCookieChanges()
150-
// Non-Firefox browsers use CDP for these instead
151167
if (isFirefox) {
168+
// Non-Firefox browsers use CDP for this instead
152169
listenToDownloads()
153-
listenToOnBeforeHeaders()
170+
// if BiDi is enabled, BiDi will handle the network interception.
171+
// Otherwise, CDP does not support it for Firefox and we need to listen for it here.
172+
const isBiDiTurnedOn = await isBiDiEnabled(config)
173+
174+
if (!isBiDiTurnedOn) {
175+
listenToOnBeforeHeaders()
176+
}
154177
}
155178
})
156179

0 commit comments

Comments
 (0)