chore: include recent console logs in results (#689)

This commit is contained in:
Pavel Feldman 2025-07-17 14:58:44 -07:00 committed by GitHub
parent c97bc6e2ae
commit 5bfff0a059
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 103 additions and 51 deletions

View file

@ -161,14 +161,13 @@ export class Context {
});
const result: string[] = [];
result.push(`- Ran Playwright code:
result.push(`### Ran Playwright code
\`\`\`js
${code.join('\n')}
\`\`\`
`);
\`\`\``);
if (this.modalStates().length) {
result.push(...this.modalStatesMarkdown());
result.push('', ...this.modalStatesMarkdown());
return {
content: [{
type: 'text',
@ -177,6 +176,13 @@ ${code.join('\n')}
};
}
const messages = tab.takeRecentConsoleMessages();
if (messages.length) {
result.push('', `### New console messages`);
for (const message of messages)
result.push(`- ${trim(message.toString(), 100)}`);
}
if (this._downloads.length) {
result.push('', '### Downloads');
for (const entry of this._downloads) {
@ -185,15 +191,16 @@ ${code.join('\n')}
else
result.push(`- Downloading file ${entry.download.suggestedFilename()} ...`);
}
result.push('');
}
if (captureSnapshot && tab.hasSnapshot()) {
if (this.tabs().length > 1)
result.push(await this.listTabsMarkdown(), '');
result.push('', await this.listTabsMarkdown());
if (this.tabs().length > 1)
result.push('### Current tab');
result.push('', '### Current tab');
else
result.push('', '### Page state');
result.push(
`- Page URL: ${tab.page.url()}`,
@ -346,3 +353,9 @@ ${code.join('\n')}
return result;
}
}
function trim(text: string, maxLength: number) {
if (text.length <= maxLength)
return text;
return text.slice(0, maxLength) + '...';
}