fix console/errors
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user