Skip to content

fix tab page history so we can restore if page tab is closed - #65

Merged
Dingway98 merged 1 commit into
mainfrom
fix/tab-stack-history
Nov 24, 2025
Merged

fix tab page history so we can restore if page tab is closed#65
Dingway98 merged 1 commit into
mainfrom
fix/tab-stack-history

Conversation

@Dingway98

@Dingway98 Dingway98 commented Nov 24, 2025

Copy link
Copy Markdown
Contributor

Note

Stops global auto-switching on new tabs, adds per-task and per-page scoped tab tracking with auto-follow and retries, and bumps version to 1.0.4.

  • Agent page/tab scoping
    • Stop auto-switching this._currentPage on context page events to preserve scoped interactions.
    • Add per-task tab following in executeTask/executeTaskAsync by tracking activeTaskPage and updating when a child tab opens; ensure listener cleanup.
    • Enhance executeSingleAction to accept Page | (() => Page), lock to initialPage, and abort with 409 on context switches; use initialPage for CDP/runtime and debug.
  • HyperPage wrapper
    • Introduce per-page tab stack (push on opener, pop on close) to determine getActivePage.
    • Wire ai/aiAsync to scoped getActivePage and keep background tasks auto-following.
    • Add aiAction retries when page context switches (tab changes) and brief stabilization waits.
    • Ensure persistent page listener with cleanup to track tab flow.
  • Version
    • Bump package.json to 1.0.4.

Written by Cursor Bugbot for commit 5099e1a. This will update automatically on new commits. Configure here.

Comment thread src/agent/index.ts

// History Stack: [Root, Tab1, Tab2, ...]
const pageStack: Page[] = [page];
const getActivePage = () => pageStack[pageStack.length - 1];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Empty page stack returns undefined

When all pages in the pageStack are closed (including the root page), getActivePage() returns undefined because it accesses pageStack[pageStack.length - 1] on an empty array. This undefined value is then passed to executeTask, executeSingleAction, and executeTaskAsync, causing runtime errors since these methods expect a valid Page object. The page stack needs to handle the empty state or prevent the root page from being removed.

Fix in Cursor Fix in Web

Comment thread src/agent/index.ts
const activePage = await this.getCurrentPage();
return this.executeSingleAction(instruction, activePage, params);
// Listen for close on the root page
page.on("close", () => handleClose(page));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Memory leak from accumulating close event listeners

When setupHyperPage is called multiple times on the same page (e.g., through repeated getPages() calls), new close event listeners are added to pages without removing the old ones. The _scopeListenerCleanup function only removes the context's page listener but doesn't clean up the close listeners attached to individual pages at lines 1151 and 1167. This causes close listeners to accumulate, creating a memory leak where each page holds references to multiple obsolete closures.

Additional Locations (1)

Fix in Cursor Fix in Web

@Dingway98
Dingway98 merged commit 7a62428 into main Nov 24, 2025
5 checks passed
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.

2 participants