fix console/errors

This commit is contained in:
Chris Tate
2026-01-11 00:21:26 -06:00
parent 5fda532ae2
commit 627c88888e
2 changed files with 29 additions and 2 deletions
-2
View File
@@ -1160,7 +1160,6 @@ async function handleConsole(command: ConsoleCommand, browser: BrowserManager):
return successResponse(command.id, { cleared: true });
}
browser.startConsoleTracking();
const messages = browser.getConsoleMessages();
return successResponse(command.id, { messages });
}
@@ -1171,7 +1170,6 @@ async function handleErrors(command: ErrorsCommand, browser: BrowserManager): Pr
return successResponse(command.id, { cleared: true });
}
browser.startErrorTracking();
const errors = browser.getPageErrors();
return successResponse(command.id, { errors });
}
+29
View File
@@ -459,6 +459,29 @@ export class BrowserManager {
const page = await context.newPage();
this.pages.push(page);
this.activePageIndex = 0;
// Automatically start console and error tracking
this.setupPageTracking(page);
}
/**
* Set up console and error tracking for a page
*/
private setupPageTracking(page: Page): void {
page.on('console', (msg) => {
this.consoleMessages.push({
type: msg.type(),
text: msg.text(),
timestamp: Date.now(),
});
});
page.on('pageerror', (error) => {
this.pageErrors.push({
message: error.message,
timestamp: Date.now(),
});
});
}
/**
@@ -474,6 +497,9 @@ export class BrowserManager {
this.pages.push(page);
this.activePageIndex = this.pages.length - 1;
// Set up tracking for the new page
this.setupPageTracking(page);
return { index: this.activePageIndex, total: this.pages.length };
}
@@ -498,6 +524,9 @@ export class BrowserManager {
this.pages.push(page);
this.activePageIndex = this.pages.length - 1;
// Set up tracking for the new page
this.setupPageTracking(page);
return { index: this.activePageIndex, total: this.pages.length };
}