Skip to content

fix: close old pages before clearing map during handoff#787

Open
km-git007 wants to merge 1 commit intogarrytan:mainfrom
km-git007:fix/handoff-page-resource-leak
Open

fix: close old pages before clearing map during handoff#787
km-git007 wants to merge 1 commit intogarrytan:mainfrom
km-git007:fix/handoff-page-resource-leak

Conversation

@km-git007
Copy link
Copy Markdown

When handing off from headless to headed mode, old pages were removed from the pages map without being explicitly closed. This left Playwright Page objects dangling with their event listeners and resources intact, causing a resource leak.

The pattern for cleanup should match closeAllPages() and recreateContext(), which both explicitly close pages before clearing the map:

for (const page of this.pages.values()) {
await page.close().catch(() => {});
}
this.pages.clear();

This ensures Playwright resources are properly released when switching to headed mode, preventing memory accumulation on repeated handoff/resume cycles.

Fixes resource leak in interactive handoff workflow (headless → headed mode).

When handing off from headless to headed mode, old pages were removed from
the pages map without being explicitly closed. This left Playwright Page
objects dangling with their event listeners and resources intact, causing
a resource leak.

The pattern for cleanup should match closeAllPages() and recreateContext(),
which both explicitly close pages before clearing the map:

  for (const page of this.pages.values()) {
    await page.close().catch(() => {});
  }
  this.pages.clear();

This ensures Playwright resources are properly released when switching to
headed mode, preventing memory accumulation on repeated handoff/resume cycles.

Fixes resource leak in interactive handoff workflow (headless → headed mode).
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