From 38098c6153330823299c974767f8be3556e63b78 Mon Sep 17 00:00:00 2001 From: "Tommy D. Rossi" Date: Wed, 18 Feb 2026 23:13:23 +0100 Subject: [PATCH] fix stale popup warnings leaking across executions on error path Oracle review found that popupWarnings was only drained on the success path. If execute() threw, warnings would leak into the next unrelated call. Now drain in both success and catch paths. Also guard indexOf returning -1 when popup isn't in context.pages() yet. --- playwriter/src/executor.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/playwriter/src/executor.ts b/playwriter/src/executor.ts index 797add1..38fc669 100644 --- a/playwriter/src/executor.ts +++ b/playwriter/src/executor.ts @@ -318,7 +318,8 @@ export class PlaywrightExecutor { page.on('popup', (popup) => { const context = page.context() const pages = context.pages() - const pageIndex = pages.indexOf(popup) + const rawIndex = pages.indexOf(popup) + const pageIndex = rawIndex >= 0 ? String(rawIndex) : 'unknown' const url = popup.url() this.popupWarnings.push( `Popup window detected (page index ${pageIndex}, url: ${url}). ` + @@ -918,12 +919,16 @@ export class PlaywrightExecutor { this.logger.error('Error in execute:', errorStack) const logsText = formatConsoleLogs(consoleLogs, 'Console output (before error)') + const popupText = this.popupWarnings.length > 0 + ? this.popupWarnings.map((w) => `[WARNING] ${w}`).join('\n') + '\n' + : '' + this.popupWarnings = [] const resetHint = isTimeoutError ? '' : '\n\n[HINT: If this is an internal Playwright error, page/browser closed, or connection issue, call reset to reconnect.]' return { - text: `${logsText}\nError executing code: ${error.message}\n${errorStack}${resetHint}`, + text: `${logsText}${popupText}\nError executing code: ${error.message}\n${errorStack}${resetHint}`, images: [], isError: true, }