Skip to content

fix: let adoptContext and Connect To Browser index contexts like New Context - #5370

Merged
aaltat merged 1 commit into
MarketSquare:mainfrom
aaltat:adopted-context-node-defaults
Oct 21, 2026
Merged

aaltat merged 1 commit into
MarketSquare:mainfrom
aaltat:adopted-context-node-defaults

Conversation

@aaltat

@aaltat aaltat commented Oct 20, 2026

Copy link
Copy Markdown
Member

Summary

Node only, no proto change. A follow-up to #5318 and #5326, and the second step of moving the
registration of adopted contexts into Browser (#5369 was the first).

adoptContext now does two things that every extension had to do itself:

 extensionKeywordCall
   adoptContext(context, options)
-    _indexContextWithPages(context, undefined, ...)
+    _indexContextWithPages(context, <defaultTimeout of the call>, ...)
-    return { browserId, contextId, pageId }
+    return { browserId, contextId, pageId, videoPath }   # video of the active page, or null
 async function openAdoptedPersistentContext(..., playwright, adoptContext) {
     ...
-    context.setDefaultTimeout(defaultTimeout);
     return adoptContext(context, { onClose });

Connect To Browser indexed the pages that already exist in the connected browser without their
close listener (#5368). It now indexes each page through _newPage; the last page stays active,
as before:

 addBrowser
   for each context
-    pageStack = context.pages().map(indexedPage)          # no close listener
+    _createIndexedContext(context)
+    for each page not yet indexed
+      pageStack.push(_newPage(context, page))             # removes itself on close

New Context on a persistent or adopted browser says so:

-Trying to create a new context when a persistentContext is active
+Cannot create a new context in chromium, because its context is persistent or adopted. Open a new browser first.

Fixes #5368

Evidence

  • Before: connected over CDP to a Chromium with one open page, closed that page from its own
    browser, then Switch Browser to the connected one:
    page.bringToFront: Target page, context or browser has been closed.
    After: the closed page leaves the page stack; Get Page Ids returns [].
  • New Jest tests, each red before its change:
    • an adopted context gets the default timeout of the call
    • adoptContext returns the video path of the active page; null without video or pages
    • addBrowser removes a page that existed when the browser was connected once it closes
    • addBrowser indexes a page once when the context reports it while the browser is added
    • New Context on an adopted browser explains why it fails
  • Acceptance: the test extension no longer sets the timeout nor reads the video path, so
    An Adopted Context Gets The Library Timeout and the recording tests from test: pin the video size of an adopted context through a library built on Browser #5369 now cover both
    through the extension call. 05_JS_Tests 61/61; 01_Browser_Management passes except two
    Firefox tests whose browser fails to launch locally (CI runs them).

Merge Danger

Door: two-way

Blast Radius: Connect To Browser

adoptContext is unreleased, so its changes reach no users. Connect To Browser is released: a
closed page that existed at connect time no longer stays in the catalog or stays the active page.
The changed error message of New Context breaks a test that matches the old text.

🤖 Generated with Claude Code

…Context

- adoptContext gives the adopted context the default timeout of the extension
  call, so an extension no longer calls setDefaultTimeout itself.
- adoptContext returns the video path of the active page as videoPath, so an
  extension no longer reads it from the page itself.
- Connect To Browser indexes the pages that already exist in the connected
  browser with their close listener, so a closed page leaves the page stack
  instead of staying the active page. The last page stays active, as before.
- New Context on a browser without a browser object says that its context is
  persistent or adopted.

Fixes MarketSquare#5368

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aaltat
aaltat merged commit 89c1314 into MarketSquare:main Oct 21, 2026
30 checks passed
@aaltat
aaltat deleted the adopted-context-node-defaults branch October 21, 2026 04:04
d-biehl pushed a commit to robotcodedev/robotframework-electron-vscode that referenced this pull request Oct 22, 2026
Browser registers an adopted context itself now, from the report that
adoptContext writes on the stream of the extension call
(MarketSquare/robotframework-browser#5372). It gives the context the
library timeout, returns the video of its active page
(MarketSquare/robotframework-browser#5370), and adoptContext takes the
page to make active.

electron.js passes the first window's own page as activePage, so Browser
makes the window the active page, not a WebContentsView or <webview>
that Playwright saw first, and reports the window's video. Start
Electron Application no longer switches pages after the start and no
longer calls register_adopted_context; it returns the page id and the
video path that Browser reported. When the first window closes during
the start, Browser keeps the page that Playwright saw first, and the
returned video is that page's.

Co-authored-by: Tatu Aalto <aalto.tatu@gmail.com>
d-biehl added a commit to d-biehl/robotframework-browser.org that referenced this pull request Oct 22, 2026
…itself

Browser now registers an adopted context from the report of the extension call (MarketSquare/robotframework-browser#5372), gives it the library timeout and returns the video of its active page (MarketSquare/robotframework-browser#5370), and adoptContext takes an activePage. The examples no longer set the timeout, read the video path or call register_adopted_context, and the page describes activePage, the registration and videoPath.
d-biehl added a commit to robotcodedev/robotframework-electron-vscode that referenced this pull request Oct 23, 2026
MarketSquare/robotframework-browser#5372 replaced register_adopted_context
before any release: call_js_keyword registers an adopted context from the
report of the extension call. The background notes now say so, together
with the timeout, the video and the activePage that adoptContext handles
since MarketSquare/robotframework-browser#5370.
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.

Pages that exist when Connect To Browser connects stay in the page stack after they close

1 participant