Skip to content

chore(browser-automation): add browsers-automation package, which contains the CDPBridgeAdapter#34232

Open
AtofStryker wants to merge 2 commits into
feat/injection-packagefrom
feat/browser-automation-adapter
Open

chore(browser-automation): add browsers-automation package, which contains the CDPBridgeAdapter#34232
AtofStryker wants to merge 2 commits into
feat/injection-packagefrom
feat/browser-automation-adapter

Conversation

@AtofStryker

@AtofStryker AtofStryker commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Stack 3/4 — base is the injection-package PR (feat/injection-package). Review/merge the stack in order.

  • Closes

Additional details

Adds @packages/browser-automation: the transport adapters that actually register the injection bundle in the browser. Builds on @packages/injection (previous stack entry).

  • CdpBridgeInjectionAdapter assembles the @packages/injection bundle + the runner sources (from @packages/resolve-dist) and registers it over CDP Page.addScriptToEvaluateOnNewDocument, so it runs before any app script and survives cy.reload() / same-tab navigations. It registers for a caller-supplied primary origin and re-registers (detach + attach) when the top-frame origin changes, keyed on the injector-reduced (super)domain so same-origin navigations don't churn.
  • AbstractBridgeInjection is the transport-agnostic base (assembles the injectable source); CdpBridgeInjectionAdapter is the CDP implementation. Kept free of any @packages/server dependency to avoid a cycle.

Part of the HTTP/2 program (#33919): #33849 (full / same-origin), #33859 (cross-origin).


Note

Medium Risk
Touches core AUT bridge delivery (script assembly and CDP registration) for upcoming proxy-bypass behavior, but the package is not integrated into the runner yet and is covered by focused unit tests.

Overview
Introduces @packages/browser-automation, an internal package that will install the Cypress AUT bridge when traffic no longer goes through the proxy (HTTP/2 / bypass path). Nothing in @packages/server is wired yet; knip is updated to track the new workspace.

AbstractBridgeInjection builds the injectable script by combining the @packages/injection bundle, runner sources from @packages/resolve-dist, and serialized document-domain / cross-origin config into a call to CypressInjection.injectAutBridge(...). CdpBridgeInjectionAdapter registers that script via CDP Page.addScriptToEvaluateOnNewDocument, with lifecycle keyed on DocumentDomainInjection.getOrigin so repeat calls for the same reduced origin are no-ops and real origin changes trigger remove-then-add. Unparseable primary origins throw instead of skipping injection.

Exports the CDP adapter and a local ForAutBridgeInjection port; CDP send is typed locally to avoid a @packages/server dependency. Vitest covers register/re-register behavior, subdomain vs superdomain keying, and assembled script shape.

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

Steps to test

  • yarn workspace @packages/browser-automation test — the adapter's register / re-register (detach + attach) lifecycle and the assembled-script shape.
  • yarn workspace @packages/browser-automation check-ts / lint.

How has the user experience changed?

No change. New internal package; wired into the server in the next stack entry.

PR Tasks

  • [na] Is there an associated issue with maintainer approval for PR submission?
  • Have tests been added/updated?
  • [na] Has a PR for user-facing changes been opened in cypress-documentation?
  • [na] Have API changes been updated in the type definitions?

@AtofStryker AtofStryker self-assigned this Jul 7, 2026
@AtofStryker AtofStryker force-pushed the feat/injection-package branch from 3422240 to 71c833c Compare July 7, 2026 13:10
@AtofStryker AtofStryker changed the title feat(browser-automation): add CDP AUT bridge injection adapter chore(browser-automation): add browsers-automation package, which contains the CDPBridgeAdapter Jul 7, 2026
@AtofStryker AtofStryker force-pushed the feat/browser-automation-adapter branch from 7bc4076 to fec02dc Compare July 7, 2026 14:23

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit fec02dc. Configure here.


this.scriptIdentifier = identifier
this.injectedOriginKey = originKey
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overlapping inject calls race

Medium Severity

inject has no in-flight guard, so overlapping calls (different origins or a re-register still awaiting buildScript / CDP) can each pass the idempotency check, register multiple Page.addScriptToEvaluateOnNewDocument scripts, and leave stale identifiers in CDP while internal state tracks only the last registration.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit fec02dc. Configure here.

@cypress

cypress Bot commented Jul 7, 2026

Copy link
Copy Markdown

cypress    Run #72186

Run Properties:  status check passed Passed #72186  •  git commit 6c90248734: feat(browser-automation): add CDP AUT bridge injection adapter
Project cypress
Branch Review feat/browser-automation-adapter
Run status status check passed Passed #72186
Run duration 19m 36s
Commit git commit 6c90248734: feat(browser-automation): add CDP AUT bridge injection adapter
Committer Bill Glesias
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 6
Tests that did not run due to a developer annotating a test with .skip  Pending 1133
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 27494
View all changes introduced in this branch ↗︎
UI Coverage  65.33%
  Untested elements 26  
  Tested elements 49  
Accessibility  99.03%
  Failed rules  0 critical   3 serious   1 moderate   0 minor
  Failed elements 18  

@AtofStryker AtofStryker force-pushed the feat/injection-package branch from 71c833c to 4283fcc Compare July 7, 2026 18:15
@AtofStryker AtofStryker force-pushed the feat/browser-automation-adapter branch from fec02dc to 45f6857 Compare July 7, 2026 18:16
…jection

Introduce @packages/injection: the page-context, automation-client-agnostic
logic that decides what Cypress driver code to inject into the AUT and bundles
it as a default-exported string for an automation client (CDP today, BiDi later)
to register — the HTTP/2 proxy-bypass path can no longer rewrite AUT HTML at the
proxy.

- injectAutBridge sets document.domain up front (via the real DocumentDomainInjection),
  then resolves the per-frame injection level and runs the matching runner source.
- Level resolution is superdomain-aware through the injector, and takes the primary
  origin as an argument rather than reading window.top.location, which a cross-subdomain
  AUT frame can't access under web security.
- Levels are none | full | cross-origin (no separate partial: document.domain glue is
  applied up front for every frame, so a non-AUT frame has nothing left to inject).
- Bundled by rollup into a self-contained IIFE with no runtime dependencies.

Tests: vitest unit specs for the pure level resolution and per-frame signal gathering,
plus an integration spec that exercises the whole chain unmocked. v8 coverage with the
html reporter enabled; .yarnclean keeps istanbul-reports' html assets so it can render.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@AtofStryker AtofStryker force-pushed the feat/injection-package branch from 4283fcc to a7f3f23 Compare July 7, 2026 18:53
New @packages/browser-automation: browser-side automation adapters for the HTTP/2
proxy-bypass path, where the MITM proxy is no longer on the AUT traffic path to
rewrite HTML.

- CdpBridgeInjectionAdapter installs the Cypress bridge (window.Cypress) into the AUT
  via Page.addScriptToEvaluateOnNewDocument, so it runs before any app script and
  survives cy.reload() / same-tab navigations. It registers for a primary origin
  supplied by the caller and re-registers (detach + attach) when that origin changes,
  keyed on the injector-reduced (super)domain so same-origin navigations don't churn.
- AbstractBridgeInjection: transport-agnostic base that wraps the @packages/injection
  document-context bundle and serializes the primary origin, document.domain config,
  cross-origin config, and runner sources (from @packages/resolve-dist) into the
  injectAutBridge(...) call. Concrete adapters implement inject() per transport.
- Depends on @packages/injection, @packages/resolve-dist, and @packages/network-tools;
  deliberately free of any @packages/server dependency to avoid a cycle.

Spike for #33849 (full / same-origin) and #33859 (cross-origin).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@AtofStryker AtofStryker force-pushed the feat/browser-automation-adapter branch from 45f6857 to 6c90248 Compare July 7, 2026 21:44
@AtofStryker AtofStryker force-pushed the feat/injection-package branch from a7f3f23 to 0508e2e Compare July 7, 2026 22:16
@cacieprins cacieprins mentioned this pull request Jul 10, 2026
8 tasks
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.

1 participant