-
Notifications
You must be signed in to change notification settings - Fork 1k
dont close new opened tabs #844
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 5ae360d The changes in this PR will be included in the next version bump. 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
Major update to tab management in Stagehand that stops automatically closing new tabs, essential for websites requiring original tabs to remain open during navigation.
- Added live page proxy in
lib/index.ts
that dynamically tracks the focused page/tab - New page event listener in
lib/StagehandContext.ts
automatically initializes new tabs as StagehandPages - Removed automatic tab closure from
lib/handlers/actHandlerUtils.ts
andlib/handlers/agentHandler.ts
- Added comprehensive tab handling tests with
evals/tasks/tab_handling.ts
,multi_tab.ts
, andagent/kayak.ts
- Memory management consideration: tabs must now be manually closed as they're no longer automatically cleaned up
11 files reviewed, 7 comments
Edit PR Review Bot Settings | Greptile
const handler: ProxyHandler<T> = { | ||
get: (_t, prop, receiver) => { | ||
const real = this.stagehandPage.page as unknown as T; | ||
const value = Reflect.get(real, prop, receiver); | ||
return typeof value === "function" ? value.bind(real) : value; | ||
}, | ||
set: (_t, prop, value) => { | ||
const real = this.stagehandPage.page as unknown as T; | ||
Reflect.set(real, prop, value); | ||
return true; | ||
}, | ||
has: (_t, prop) => prop in (this.stagehandPage.page as unknown as T), | ||
getPrototypeOf: () => proto, | ||
}; | ||
|
||
return new Proxy(target, handler); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: The proxy handler doesn't implement deleteProperty
, defineProperty
, or ownKeys
. This could cause issues with property deletion and object property enumeration.
if (!this._livePageProxy) { | ||
this._livePageProxy = this.createLivePageProxy<Page>(); | ||
} | ||
return this._livePageProxy; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v nice
🔄 Feature Parity Issue Created An issue has been automatically created in the Python SDK repository to track parity implementation: |
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] ### Patch Changes - [#856](#856) [`8a43c5a`](8a43c5a) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - set download behaviour by default - [#857](#857) [`890ffcc`](890ffcc) Thanks [@miguelg719](https://github.com/miguelg719)! - return "not-supported" for elements inside the shadow-dom - [#844](#844) [`64c1072`](64c1072) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - don't automatically close tabs - [#860](#860) [`b077d3f`](b077d3f) Thanks [@miguelg719](https://github.com/miguelg719)! - Set default schema on extract options with no schema - [#842](#842) [`8bcb5d7`](8bcb5d7) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - improved handling for OS level dropdowns - [#846](#846) [`7bf10c5`](7bf10c5) Thanks [@miguelg719](https://github.com/miguelg719)! - Filter attaching to target worker / shared_worker ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies \[[`8a43c5a`](8a43c5a), [`890ffcc`](890ffcc), [`64c1072`](64c1072), [`b077d3f`](b077d3f), [`8bcb5d7`](8bcb5d7), [`7bf10c5`](7bf10c5)]: - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies \[[`8a43c5a`](8a43c5a), [`890ffcc`](890ffcc), [`64c1072`](64c1072), [`b077d3f`](b077d3f), [`8bcb5d7`](8bcb5d7), [`7bf10c5`](7bf10c5)]: - @browserbasehq/[email protected] Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
- Add live page proxy that dynamically tracks the focused page - Implement context event listener to initialize new pages automatically - Remove automatic tab closing behavior in act_handler_utils and cua_handler - Keep both original and new tabs open when new pages are created - Ensure stagehand.page always references the current active page This implementation matches the behavior of browserbase/stagehand#844
* feat: port new page handling from JS Stagehand PR #844 - Add live page proxy that dynamically tracks the focused page - Implement context event listener to initialize new pages automatically - Remove automatic tab closing behavior in act_handler_utils and cua_handler - Keep both original and new tabs open when new pages are created - Ensure stagehand.page always references the current active page This implementation matches the behavior of browserbase/stagehand#844 * Update stagehand/handlers/cua_handler.py * Update stagehand/handlers/act_handler_utils.py --------- Co-authored-by: Arun Patro <[email protected]> Co-authored-by: Miguel <[email protected]>
* feat: don't close new opened tabs (#161) * feat: port new page handling from JS Stagehand PR #844 - Add live page proxy that dynamically tracks the focused page - Implement context event listener to initialize new pages automatically - Remove automatic tab closing behavior in act_handler_utils and cua_handler - Keep both original and new tabs open when new pages are created - Ensure stagehand.page always references the current active page This implementation matches the behavior of browserbase/stagehand#844 * Update stagehand/handlers/cua_handler.py * Update stagehand/handlers/act_handler_utils.py --------- Co-authored-by: Arun Patro <[email protected]> Co-authored-by: Miguel <[email protected]> * formatting, logs * changeset * fix: update mock_stagehand_client fixture to set internal page properties The page property is now read-only (returns LivePageProxy), so tests need to set the internal _original_page and _active_page properties instead * feat: add page stability check to LivePageProxy for async operations Ensures async operations wait for any pending page switches to complete * formatting * fix: prevent deadlock in page navigation and add page stability tests - Initialize _page_switch_lock in Stagehand constructor - Skip page stability check for navigation methods (goto, reload, go_back, go_forward) - Use lock when switching active pages in context - Add comprehensive tests for LivePageProxy functionality * consolidate original and active page to just one page * Update stagehand/context.py * Update .changeset/gorilla-of-strongest-novelty.md * timeouts * python 3.10 or less compatibility --------- Co-authored-by: Arun Patro <[email protected]> Co-authored-by: Arun Patro <[email protected]> Co-authored-by: Filip Michalsky <[email protected]>
why
page.goto()
with the URL of the new tab, and immediately close the old tabwhat changed
index.ts
which always points to thefocused
page/tabStagehandContext.ts
which listens for new pages, and initializes them as Stagehand pagesconst page = stagehand.page
and then usepage
throughout their code, they expectpage
to always point to the "focused" pagetest plan
act
evals that open & close tabsact
,regression
andcombination
evals