Repository navigation
[fix]: adopt pre-existing and nested cross-origin iframes (#3262) - #3339
Conversation
# why `BrowserContext` only adopts an OOPIF session when its main frame is already in a page's frame graph, or when the parent session later emits `Page.frameAttached` for it. Two cases never get that event, so the child session stays in `pendingOopifByMainFrame` forever and snapshots/`act` can't see inside the iframe: 1. Bootstrapping against tabs that already contain a loaded cross-origin iframe (reconnect, or an extension service-worker restart): the parent's `Page.getFrameTree` omits remote frames, and no new `frameAttached` fires. 2. An OOPIF nested inside another OOPIF. Two related gaps: - A parent `Page.frameAttached` that arrives after the OOPIF was adopted gives ownership back to the parent session (`FrameRegistry.onFrameAttached` trusts the emitter). - A `frameAttached` that adds the frame a pending OOPIF is waiting on (e.g. a same-site wrapper frame) didn't retry the other pending OOPIFs. Repro: open a page with a cross-origin iframe, then start or reconnect Stagehand against that tab. The iframe's frame id never appears in the page's frame tree, and its contents are missing from snapshots. # what changed - The child-attach path falls back to the page that owns the child root's `parentId`, taken from the child's own `Page.getFrameTree`. If that page isn't known yet, the parent id is recorded, and the child is adopted once the page registers, a parent OOPIF is adopted, or a `frameAttached` reports the parent frame. This also covers nesting. - Adopted OOPIF sessions are tracked per frame, so a later parent `frameAttached` no longer takes ownership while the child session is alive. - Consolidated the owner lookup into `findPageOwningFrame` and the adoption steps into `adoptOopif`. # test plan - New `packages/extension/tests/understudy-context-oopif-adoption.test.ts` drives the real `BrowserContext` + `CdpConnection` over a scripted fake transport. Cases: pre-existing iframe; iframe attaching before its page registers; late parent `frameAttached` keeps the child owner; nested OOPIF; waiting OOPIFs adopted once their wrapper frame is reported. Each fails on `main` without its part of the fix. - The same logic was validated against real headless Chrome as a patch on 3.5.0. - `pnpm check` (44/44) and extension unit tests (1059 passed). Python checks weren't run locally. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes adoption of cross-origin iframes that were already loaded when Stagehand attached (reconnect, extension restarts) or that are nested inside another cross-origin iframe, so snapshots and actions can see inside them. **Bug Fixes** - The child attach path now falls back to the page that owns the child's parent frame, and retries all pending OOPIFs once that page registers or reports the frame. - A late parent `Page.frameAttached` no longer takes ownership of an already-adopted OOPIF session. - Tests drive the real `BrowserContext` over a scripted fake transport; each case fails on `main`. - The embedded Go extension asset was regenerated, including a merge from `main` that resolved its zip; CI's `extensionpack --check` should verify it. <sup>Written for commit 2b14e5d. Summary will update on new commits.</sup> <a href="https://cubic.dev/pr/browserbase/stagehand/pull/3262?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <!-- End of auto-generated description by cubic. --> --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
🦋 Changeset detectedLatest commit: f56cf36 The changes in this PR will be included in the next version bump. This PR includes changesets to release 23 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
All reported issues were addressed across 3 files
Architecture diagram
sequenceDiagram
participant B as Browser Target
participant C as CdpConnection
participant BC as BrowserContext
participant FR as FrameRegistry
participant P as Page
Note over B,BC: CDP Session Attachment
B->>C: Target.attachedToTarget (OOPIF session)
C->>BC: handleAttachedToTarget(sessionId, targetInfo, parentSessionId)
alt OOPIF target type
BC->>C: Page.getFrameTree (child session)
C-->>BC: frameTree {frame: childId, parentId}
alt Parent frame known
BC->>BC: findPageOwningFrame(childId) ?? findPageOwningFrame(parentId)
alt Owner found
BC->>BC: adoptOopif(owner, session, childMainId)
BC->>P: adoptOopifSession(session, childMainId)
BC->>BC: adoptedOopifSessionByFrame.set(childMainId, sessionId)
BC->>BC: adoptPendingOopifsByParent()
else No owner yet
BC->>BC: pendingOopifByMainFrame.set(childId, sessionId)
BC->>BC: pendingOopifParentByMainFrame.set(childId, parentId)
end
end
end
Note over BC,P: Page Registration with Pre-existing OOPIF
B->>C: Target.attachedToTarget (page session)
C->>BC: handleAttachedToTarget(sessionId, pageTarget)
BC->>C: Page.getFrameTree
C-->>BC: frameTree {rootFrame}
BC->>BC: adoptPendingOopifsByParent()
loop For each pending OOPIF
BC->>BC: findPageOwningFrame(parentFrameId)
alt Parent now owned by page
BC->>BC: adoptOopif(owner, childSession, childFrameId)
end
end
Note over B,P: Late Parent frameAttached Event
B->>C: Page.frameAttached {frameId, parentFrameId}
C->>BC: onFrameAttached(owner, evt)
alt frameId in adoptedOopifSessionByFrame
Note over BC: Skip ownership transfer - child session remains owner
else New frame, not adopted
BC->>P: onFrameAttached(frameId, parentFrameId, session)
BC->>BC: adoptPendingOopifsByParent()
end
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
|
@cubic-dev-ai review |
@seanmcguire12 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
All reported issues were addressed across 4 files
Architecture diagram
sequenceDiagram
participant BT as Browser Target
participant BC as BrowserContext
participant CDP as CdpConnection
participant PG as Page
participant FR as FrameRegistry
participant EC as ExecutionContextRegistry
Note over BT,EC: OOPIF Adoption Flow for Pre-existing/Nested Cross-origin Iframes
BC->>CDP: Target.setAutoAttach
CDP-->>BC: Target.attachedToTarget (page session)
BC->>CDP: Page.getFrameTree (page session)
CDP-->>BC: Frame tree (omits remote frames)
CDP->>BC: Target.attachedToTarget (OOPIF session)
BC->>CDP: Page.getFrameTree (OOPIF session)
CDP-->>BC: Frame tree with parentId
BC->>BC: findPageOwningFrame(parentFrameId)
alt Parent page found
BC->>PG: adoptOopifSession(childSession, childMainFrameId, onSeeded)
PG->>FR: seedFromFrameTree(childSession, frameTree)
FR-->>PG: Seeded frame ids
PG->>BC: onFrameTreeSeeded callback
BC->>BC: adoptPendingOopifsByParent()
BC->>EC: waitForMainWorld(session, childMainId)
else Parent page not yet registered
BC->>BC: Store in pendingOopifParentByMainFrame
BC->>BC: Store in pendingOopifByMainFrame
Note over BC: Child adoption deferred until parent known
end
Note over BC,PG: Deferred Adoption Path
CDP->>BC: Target.attachedToTarget (parent page session)
BC->>BC: Register page
BC->>BC: adoptPendingOopifsByParent()
loop While pending OOPIFs adoptable
BC->>BC: findPageOwningFrame(parentFrameId)
alt Owner found
BC->>PG: adoptOopifSession(childSession, childMainFrameId)
BC->>BC: Remove from pending maps
end
end
Note over CDP,BC: Late Parent frameAttached Event
CDP->>BC: Page.frameAttached (frameId, parentFrameId)
BC->>BC: Check adoptedOopifSessionByFrame[frameId]
alt No adopted session OR same session
BC->>PG: onFrameAttached(frameId, parentFrameId, session)
PG->>FR: Register frame ownership
BC->>BC: adoptPendingOopifsByParent()
else Adopted session still alive
Note over BC: Keep existing OOPIF owner - skip onFrameAttached
end
Note over BC,PG: Nested OOPIF Wrapper Seeding
PG->>FR: seedFromFrameTree (reveals wrapper frame)
FR-->>PG: Wrapper frameId in tree
PG->>BC: onFrameTreeSeeded()
BC->>BC: adoptPendingOopifsByParent()
BC->>BC: findPageOwningFrame(wrapperFrameId)
BC->>PG: adoptOopifSession(nestedSession, nestedFrameId)
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 5 files
Architecture diagram
sequenceDiagram
participant Ext as Extension (BrowserContext)
participant CDP as CdpConnection
participant Page as Page / FrameRegistry
participant Sites as Cross-Origin Sites
Note over Ext,Sites: OOPIF Adoption Flow (reconnect / nested iframes)
Ext->>CDP: bootstrap() - Target.getTargets
CDP-->>Ext: targets (page + iframes)
Ext->>CDP: Target.setAutoAttach (root)
CDP-->>Ext: Target.attachedToTarget (page session)
Ext->>CDP: Page.getFrameTree (page session)
alt Pre-existing OOPIF (no frameAttached event)
CDP-->>Ext: frameTree omits remote frames
Ext->>CDP: Target.attachedToTarget (iframe session)
Ext->>CDP: Page.getFrameTree (iframe session)
CDP-->>Ext: iframe frame tree with parentId
Ext->>Ext: findPageOwningFrame(childMainId) fail
Ext->>Ext: findPageOwningFrame(parentFrameId) - found
Ext->>Page: adoptOopifSession(childSession, childMainId)
Page->>Page: seedFromFrameTree - register child subtree
Page-->>Ext: onFrameTreeSeeded callback
Ext->>Ext: adoptPendingOopifsByParent() - retry queue
Ext->>Ext: installFrameEventBridges(child session)
Note over Ext,Page: Child session owns the OOPIF frames
end
alt Nested OOPIF (iframe inside another iframe)
Ext->>CDP: Page.getFrameTree (nested iframe session)
CDP-->>Ext: nested frame tree with parentId
Ext->>Ext: findPageOwningFrame(parentFrameId)
alt Parent OOPIF already adopted
Ext->>Page: adoptOopif - nested session owned by same Page
else Parent OOPIF pending
Ext->>Ext: pendingOopifParentByMainFrame.set(childMainId, parentFrameId)
Note over Ext: Child waits for parent OOPIF adoption
Ext->>Ext: adoptPendingOopifsByParent() - no owner yet
end
end
alt Late parent frameAttached event
CDP->>Ext: Page.frameAttached(frameId, parentFrameId)
Ext->>Ext: Check adoptedOopifSessionByFrame.get(frameId)
alt Session alive
Ext->>Page: onFrameAttached with child session (keeps ownership)
Note over Ext,Page: Parent emitter does NOT take ownership
else No adopted session
Ext->>Page: onFrameAttached with parent session
end
Ext->>Ext: adoptPendingOopifsByParent() - new frame may be wrapper
end
alt Pending OOPIF adoption triggered
Ext->>Ext: adoptPendingOopifsByParent()
loop while adoption progresses
Ext->>Ext: findPageOwningFrame(parentFrameId)
Ext->>Page: adoptOopif on owner page
Ext->>Ext: pendingOopifByMainFrame.delete + pendingOopifParentByMainFrame.delete
end
end
alt Page close or session detach
Ext->>Ext: Clear frameOwnerPage for page
Ext->>Ext: Remove adoptedOopifSessionByFrame entries
Note over Ext: Prevents stale ownership on late events
end
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @browserbasehq/[email protected] ### Minor Changes - [#3305](#3305) [`aeb1ba0`](aeb1ba0) Thanks [@miguelg719](https://github.com/miguelg719)! - add `browser.disconnect()`, which closes an attached Stagehand instance and the connection to a browser without closing the browser or releasing its Browserbase session (Browserbase still ends sessions without `keepAlive` on disconnect). `browser.close()` after `disconnect()` now throws (connect again to close the browser), a launched local browser receives `Browser.close` before it is terminated, browser handles expose `cdpUrl` (`cdp_url` in Python) for local browsers, and `connected` reports whether the handle still has a live connection - [#3325](#3325) [`d59afde`](d59afde) Thanks [@miguelg719](https://github.com/miguelg719)! - Add an extension watchdog for lost SDK clients ### Patch Changes - [#3339](#3339) [`44d99df`](44d99df) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - Adopt cross-origin iframes that were already loaded when Stagehand attached, or that are nested inside another cross-origin iframe, so snapshots and actions can reach them. - [#3330](#3330) [`dc8eb40`](dc8eb40) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - bump zod to 4.6.6 - [#3340](#3340) [`edb76b0`](edb76b0) Thanks [@akeimach](https://github.com/akeimach)! - Fix act, observe and extract with Claude Opus 5.5 by bumping `@ai-sdk/anthropic` and `ai` in the extension. - [#3387](#3387) [`066e875`](066e875) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fixed domain policy bypasses involving URLs with credentials, background requests, and speculative page loads - [#3383](#3383) [`1e50db6`](1e50db6) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - skip variable substitution for drag-and-drop arguments in act(). - [#3388](#3388) [`18b96f2`](18b96f2) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fix issue where calling act() prevents cross-origin iframes from loading ## @browserbasehq/[email protected] ### Patch Changes - [#3330](#3330) [`dc8eb40`](dc8eb40) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - bump zod to 4.6.6 - [#3350](#3350) [`b7a4b89`](b7a4b89) Thanks [@miguelg719](https://github.com/miguelg719)! - Save run screenshots only as PNG or JPEG files, under ./stagehand-artifacts by default - Updated dependencies [[`44d99df`](44d99df), [`dc8eb40`](dc8eb40), [`edb76b0`](edb76b0), [`066e875`](066e875), [`1e50db6`](1e50db6), [`aeb1ba0`](aeb1ba0), [`18b96f2`](18b96f2), [`d59afde`](d59afde)]: - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Minor Changes - [#3325](#3325) [`d59afde`](d59afde) Thanks [@miguelg719](https://github.com/miguelg719)! - Add an extension watchdog for lost SDK clients ### Patch Changes - [#3339](#3339) [`44d99df`](44d99df) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - Adopt cross-origin iframes that were already loaded when Stagehand attached, or that are nested inside another cross-origin iframe, so snapshots and actions can reach them. - [#3330](#3330) [`dc8eb40`](dc8eb40) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - bump zod to 4.6.6 - [#3340](#3340) [`edb76b0`](edb76b0) Thanks [@akeimach](https://github.com/akeimach)! - Fix act, observe and extract with Claude Opus 5.5 by bumping `@ai-sdk/anthropic` and `ai` in the extension. - [#3387](#3387) [`066e875`](066e875) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fixed domain policy bypasses involving URLs with credentials, background requests, and speculative page loads - [#3383](#3383) [`1e50db6`](1e50db6) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - skip variable substitution for drag-and-drop arguments in act(). - [#3388](#3388) [`18b96f2`](18b96f2) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fix issue where calling act() prevents cross-origin iframes from loading ## @browserbasehq/[email protected] ### Minor Changes - [#3305](#3305) [`aeb1ba0`](aeb1ba0) Thanks [@miguelg719](https://github.com/miguelg719)! - add `browser.disconnect()`, which closes an attached Stagehand instance and the connection to a browser without closing the browser or releasing its Browserbase session (Browserbase still ends sessions without `keepAlive` on disconnect). `browser.close()` after `disconnect()` now throws (connect again to close the browser), a launched local browser receives `Browser.close` before it is terminated, browser handles expose `cdpUrl` (`cdp_url` in Python) for local browsers, and `connected` reports whether the handle still has a live connection - [#3325](#3325) [`d59afde`](d59afde) Thanks [@miguelg719](https://github.com/miguelg719)! - Add an extension watchdog for lost SDK clients ### Patch Changes - [#3339](#3339) [`44d99df`](44d99df) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - Adopt cross-origin iframes that were already loaded when Stagehand attached, or that are nested inside another cross-origin iframe, so snapshots and actions can reach them. - [#3330](#3330) [`dc8eb40`](dc8eb40) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - bump zod to 4.6.6 - [#3340](#3340) [`edb76b0`](edb76b0) Thanks [@akeimach](https://github.com/akeimach)! - Fix act, observe and extract with Claude Opus 5.5 by bumping `@ai-sdk/anthropic` and `ai` in the extension. - [#3387](#3387) [`066e875`](066e875) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fixed domain policy bypasses involving URLs with credentials, background requests, and speculative page loads - [#3383](#3383) [`1e50db6`](1e50db6) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - skip variable substitution for drag-and-drop arguments in act(). - [#3388](#3388) [`18b96f2`](18b96f2) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fix issue where calling act() prevents cross-origin iframes from loading ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies [[`44d99df`](44d99df), [`dc8eb40`](dc8eb40), [`edb76b0`](edb76b0), [`066e875`](066e875), [`1e50db6`](1e50db6), [`aeb1ba0`](aeb1ba0), [`18b96f2`](18b96f2), [`d59afde`](d59afde)]: - @browserbasehq/[email protected] - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies []: - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies []: - @browserbasehq/[email protected] - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies [[`44d99df`](44d99df), [`dc8eb40`](dc8eb40), [`edb76b0`](edb76b0), [`066e875`](066e875), [`1e50db6`](1e50db6), [`aeb1ba0`](aeb1ba0), [`18b96f2`](18b96f2), [`d59afde`](d59afde)]: - @browserbasehq/[email protected] - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies []: - @browserbasehq/[email protected] - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies []: - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies [[`44d99df`](44d99df), [`dc8eb40`](dc8eb40), [`edb76b0`](edb76b0), [`066e875`](066e875), [`1e50db6`](1e50db6), [`aeb1ba0`](aeb1ba0), [`18b96f2`](18b96f2), [`d59afde`](d59afde)]: - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies []: - @browserbasehq/[email protected] - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies []: - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies []: - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies []: - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies []: - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies [[`44d99df`](44d99df), [`dc8eb40`](dc8eb40), [`edb76b0`](edb76b0), [`066e875`](066e875), [`1e50db6`](1e50db6), [`aeb1ba0`](aeb1ba0), [`18b96f2`](18b96f2), [`d59afde`](d59afde)]: - @browserbasehq/[email protected] - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies []: - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies []: - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies [[`44d99df`](44d99df), [`dc8eb40`](dc8eb40), [`edb76b0`](edb76b0), [`066e875`](066e875), [`1e50db6`](1e50db6), [`aeb1ba0`](aeb1ba0), [`18b96f2`](18b96f2), [`d59afde`](d59afde)]: - @browserbasehq/[email protected] - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies []: - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies []: - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - [#3330](#3330) [`dc8eb40`](dc8eb40) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - bump zod to 4.6.6 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
why
BrowserContextonly adopts an OOPIF session when its main frame is already in a page's frame graph, or when the parent session later emitsPage.frameAttachedfor it. Two cases never get that event, so the child session stays inpendingOopifByMainFrameforever and snapshots/actcan't see inside the iframe:Page.getFrameTreeomits remote frames, and no newframeAttachedfires.Two related gaps:
Page.frameAttachedthat arrives after the OOPIF was adopted gives ownership back to the parent session(
FrameRegistry.onFrameAttachedtrusts the emitter).frameAttachedthat adds the frame a pending OOPIF is waiting on (e.g. a same-site wrapper frame) didn't retry the other pending OOPIFs.Repro: open a page with a cross-origin iframe, then start or reconnect Stagehand against that tab. The iframe's frame id never appears in the page's frame tree, and its contents are missing from snapshots.
what changed
parentId, taken from the child's ownPage.getFrameTree. If that page isn't known yet, the parent id is recorded, and the child is adopted once the page registers, a parent OOPIF is adopted, or aframeAttachedreports the parent frame. This also covers nesting.frameAttachedno longer takes ownership while the child session is alive.findPageOwningFrameand the adoption steps intoadoptOopif.test plan
packages/extension/tests/understudy-context-oopif-adoption.test.tsdrives the realBrowserContext+CdpConnectionover a scripted fake transport. Cases: pre-existing iframe; iframe attaching before its page registers; late parentframeAttachedkeeps the child owner; nested OOPIF; waiting OOPIFs adopted once their wrapper frame is reported. Each fails onmainwithout its part of the fix.pnpm check(44/44) and extension unit tests (1059 passed). Python checks weren't run locally.🤖 Generated with Claude Code
Summary by cubic
Fixes adoption of cross-origin iframes that were already loaded when Stagehand attached (reconnect, extension restarts) or that are nested inside another cross-origin iframe, so snapshots and actions can see inside them.
Page.frameAttachedno longer takes ownership of an already-adopted OOPIF session while that session is alive; the parent edge is still recorded even when subtree seeding is pending or failed.BrowserContextover a scripted fake transport; each case fails onmain.Written for commit f56cf36. Summary will update on new commits.
why
what changed
test plan