feat: Log screenshots as base64 for Azure debugging
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
60246b7922
commit
61219ce5a2
1 changed files with 14 additions and 1 deletions
|
|
@ -439,6 +439,7 @@ export class BotOrchestrator {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Take a screenshot for debugging.
|
* Take a screenshot for debugging.
|
||||||
|
* Logs screenshot as base64 for easy viewing from Azure logs.
|
||||||
*/
|
*/
|
||||||
private async _takeScreenshot(name: string): Promise<void> {
|
private async _takeScreenshot(name: string): Promise<void> {
|
||||||
if (!config.screenshotOnError || !this._page) {
|
if (!config.screenshotOnError || !this._page) {
|
||||||
|
|
@ -446,6 +447,7 @@ export class BotOrchestrator {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Save to file
|
||||||
const screenshotDir = config.screenshotDir;
|
const screenshotDir = config.screenshotDir;
|
||||||
if (!fs.existsSync(screenshotDir)) {
|
if (!fs.existsSync(screenshotDir)) {
|
||||||
fs.mkdirSync(screenshotDir, { recursive: true });
|
fs.mkdirSync(screenshotDir, { recursive: true });
|
||||||
|
|
@ -453,8 +455,19 @@ export class BotOrchestrator {
|
||||||
|
|
||||||
const filename = `${this._sessionId}-${name}-${Date.now()}.png`;
|
const filename = `${this._sessionId}-${name}-${Date.now()}.png`;
|
||||||
const filepath = path.join(screenshotDir, filename);
|
const filepath = path.join(screenshotDir, filename);
|
||||||
await this._page.screenshot({ path: filepath, fullPage: true });
|
const buffer = await this._page.screenshot({ fullPage: true });
|
||||||
|
fs.writeFileSync(filepath, buffer);
|
||||||
this._logger.info(`Screenshot saved: ${filepath}`);
|
this._logger.info(`Screenshot saved: ${filepath}`);
|
||||||
|
|
||||||
|
// Also log as base64 for Azure logs (truncated for readability)
|
||||||
|
const base64 = buffer.toString('base64');
|
||||||
|
this._logger.info(`SCREENSHOT_BASE64_START:${name}`);
|
||||||
|
// Log in chunks to avoid log line limits
|
||||||
|
const chunkSize = 50000;
|
||||||
|
for (let i = 0; i < base64.length; i += chunkSize) {
|
||||||
|
this._logger.info(`SCREENSHOT_CHUNK:${base64.substring(i, i + chunkSize)}`);
|
||||||
|
}
|
||||||
|
this._logger.info(`SCREENSHOT_BASE64_END:${name}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this._logger.error('Error taking screenshot:', error);
|
this._logger.error('Error taking screenshot:', error);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue