Skip to content

refactor(server): convert cdp_automation promise chains to async/await#34245

Open
AtofStryker wants to merge 1 commit into
developfrom
refactor/automation_client_p2
Open

refactor(server): convert cdp_automation promise chains to async/await#34245
AtofStryker wants to merge 1 commit into
developfrom
refactor/automation_client_p2

Conversation

@AtofStryker

@AtofStryker AtofStryker commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator
  • Closes N/A — mechanical modernization, no associated issue (explained below)

Additional details

Stacked on #34244 (refactor/automation_client_p1) — this PR targets that branch and only adds the one commit.

This converts packages/server/lib/browsers/cdp_automation.ts off bluebird and .then/.catch chains onto native async/await. It is intended to be behavior neutral — no logic, ordering, or error-handling changes:

  • getAllCookies / getCookiesByUrl / getCookie become async functions; the explicit CDP response type annotations move from the callback parameters onto the awaited consts
  • the onRequest cases for set:cookie, set:cookies, clear:cookie, and take:screenshot await inline instead of chaining, preserving the same error messages and result shapes
  • Bluebird.mapSeries in clear:cookies becomes a sequential for...of loop — same serial execution (each cookie fetched and deleted before the next) and the same undefined entries in the result array for cookies that no longer exist
  • _updateFrameTree's new Promise with an async executor becomes an async IIFE with identical resolution semantics (never rejects, nulls the in-flight marker before resolving)

Deliberately left as-is: the two new Promise constructions in activateMainTab (an event-listener wait and a timeout race — the constructor is the right tool there), the intentionally unawaited .catch in _continueRequest (swallows late Invalid InterceptionId errors so they can't crash Cypress), and the already-native Promise.all in reset:browser:state.

This removes the last bluebird usage from this file, though bluebird remains a dependency of other server modules.

Steps to test

No behavior change to validate — the existing suites cover every converted path:

yarn workspace @packages/server test-unit -- cdp_automation_spec   # cookies, screenshot, frame tree (45 tests)
yarn workspace @packages/server test-unit -- automation            # broader automation specs (128 tests)

Also verified green: chrome_spec, electron_spec, cri-client_spec (consumers of CdpAutomation), check-ts, and lint.

How has the user experience changed?

No change.

PR Tasks

  • [na] Is there an associated issue with maintainer approval for PR submission? — purely mechanical conversion, no behavior change
  • [na] Have tests been added/updated? — intentionally none; the existing specs pin the behavior being preserved
  • [na] Has a PR for user-facing changes been opened in cypress-documentation?
  • [na] Have API changes been updated in the type definitions?

Note

Low Risk
Behavior-neutral style modernization in CDP automation with no intended logic or ordering changes; existing unit specs cover the touched paths.

Overview
Mechanical refactor in cdp_automation.ts: drops the bluebird import and rewrites cookie helpers, frame-tree updates, and several onRequest branches to native async/await instead of .then/.catch chains.

Cookie paths (getAllCookies, getCookiesByUrl, getCookie) and automation cases (set:cookie, set:cookies, clear:cookie, take:screenshot) keep the same CDP calls, error text, and return shapes; CDP response types are annotated on awaited results. clear:cookies replaces Bluebird.mapSeries with a sequential for...of loop that still deletes one cookie at a time and still pushes undefined when a cookie is missing. _updateFrameTree uses an async IIFE instead of new Promise with an async executor, with the same non-rejecting behavior and gettingFrameTree cleanup.

Intentionally unchanged: activateMainTab’s listener/timeout Promise usage, the unawaited .catch on Fetch.continueRequest, and Promise.all in reset:browser:state.

Reviewed by Cursor Bugbot for commit b1d8540. Bugbot is set up for automated code reviews on this repo. Configure here.

@cypress

cypress Bot commented Jul 8, 2026

Copy link
Copy Markdown

cypress    Run #72200

Run Properties:  status check passed Passed #72200  •  git commit ec4798a0af: refactor(server): convert cdp_automation promise chains to async/await
Project cypress
Branch Review refactor/automation_client_p2
Run status status check passed Passed #72200
Run duration 19m 55s
Commit git commit ec4798a0af: refactor(server): convert cdp_automation promise chains to async/await
Committer Bill Glesias
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 7
Tests that did not run due to a developer annotating a test with .skip  Pending 1124
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 26363
View all changes introduced in this branch ↗︎
UI Coverage  0%
  Untested elements 4  
  Tested elements 0  
Accessibility  100%
  Failed rules  0 critical   0 serious   0 moderate   0 minor
  Failed elements 0  

@AtofStryker AtofStryker self-assigned this Jul 8, 2026
@AtofStryker AtofStryker requested review from a team, cacieprins and cypress-app-bot July 8, 2026 16:00
Base automatically changed from refactor/automation_client_p1 to develop July 9, 2026 12:27
Behavior-neutral conversion of packages/server/lib/browsers/cdp_automation.ts
off bluebird and .then/.catch chains onto native async/await:

- getAllCookies / getCookiesByUrl / getCookie become async functions
- the onRequest set:cookie, set:cookies, clear:cookie, and take:screenshot
  cases await inline instead of chaining
- Bluebird.mapSeries in clear:cookies becomes a sequential for...of loop,
  preserving the serial ordering and the undefined entries for cookies that
  no longer exist
- _updateFrameTree's promise-with-async-executor becomes an async IIFE with
  identical resolution semantics

The new Promise usages in activateMainTab (event listener + timeout race)
and the intentionally unawaited .catch in _continueRequest are left as is.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@AtofStryker AtofStryker force-pushed the refactor/automation_client_p2 branch from ec4798a to b1d8540 Compare July 9, 2026 12:28
@AtofStryker AtofStryker requested a review from mschile July 10, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants