Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore: revert file output to server-based (#39038)

Pavel Feldmand620c45cd29d
diff --git a/packages/playwright/src/mcp/browser/browserServerBackend.ts b/packages/playwright/src/mcp/browser/browserServerBackend.ts
index 40e19d9413..c64037ce0c 100644
--- a/packages/playwright/src/mcp/browser/browserServerBackend.ts
+++ b/packages/playwright/src/mcp/browser/browserServerBackend.ts
@@ -17,7 +17,7 @@
import { FullConfig } from './config';
import { Context } from './context';
import { logUnhandledError } from '../log';
-import { Response, serializeResponse } from './response';
+import { Response } from './response';
import { SessionLog } from './sessionLog';
import { browserTools, filteredTools } from './tools';
import { toMcpTool } from '../sdk/tool';
@@ -68,13 +68,12 @@ export class BrowserServerBackend implements ServerBackend {
const parsedArguments = tool.schema.inputSchema.parse(rawArguments || {}) as any;
const cwd = rawArguments?._meta && typeof rawArguments?._meta === 'object' && (rawArguments._meta as any)?.cwd;
const context = this._context!;
- const response = Response.create(context, name, parsedArguments);
+ const response = Response.create(context, name, parsedArguments, cwd);
context.setRunningTool(name);
let responseObject: mcpServer.CallToolResult;
try {
await tool.handle(context, parsedArguments, response);
- const sections = await response.build();
- responseObject = await serializeResponse(context, sections, cwd ?? context.firstRootPath());
+ responseObject = await response.serialize();
this._sessionLog?.logResponse(name, parsedArguments, responseObject);
} catch (error: any) {
return {
diff --git a/packages/playwright/src/mcp/browser/response.ts b/packages/playwright/src/mcp/browser/response.ts
index 80bdf8ba2a..5fe2c39efa 100644
--- a/packages/playwright/src/mcp/browser/response.ts
+++ b/packages/playwright/src/mcp/browser/response.ts
@@ -28,28 +28,27 @@ import type { Context } from './context';
export const requestDebug = debug('pw:mcp:request');
-type Result = {
- text?: string;
- data?: Buffer;
- isBase64?: boolean;
- title: string;
- file?: {
- prefix: string;
- ext: string;
- suggestedFilename?: string;
- contentType?: string;
- };
+type FilenameTemplate = {
+ prefix: string;
+ ext: string;
+ suggestedFilename?: string;
+};
+
+type ResolvedFile = {
+ fileName: string;
+ relativeName: string;
+ printableLink: string;
};
export type Section = {
title: string;
- content: Result[];
+ content: string[];
isError?: boolean;
codeframe?: 'yaml' | 'js';
};
export class Response {
- private _results: Result[] = [];
+ private _results: string[] = [];
private _errors: string[] = [];
private _code: string[] = [];
private _context: Context;
@@ -58,30 +57,65 @@ export class Response {
readonly toolName: string;
readonly toolArgs: Record<string, any>;
+ private _relativeTo: string | undefined;
+ private _imageResults: { data: Buffer, imageType: 'png' | 'jpeg' }[] = [];
- private constructor(ordinal: number, context: Context, toolName: string, toolArgs: Record<string, any>) {
+ private constructor(context: Context, toolName: string, toolArgs: Record<string, any>, relativeTo?: string) {
this._context = context;
this.toolName = toolName;
this.toolArgs = toolArgs;
+ this._relativeTo = relativeTo ?? context.firstRootPath();
}
- static _ordinal = 0;
+ static create(context: Context, toolName: string, toolArgs: Record<string, any>, relativeTo?: string) {
+ return new Response(context, toolName, toolArgs, relativeTo);
+ }
+
+ private _computRelativeTo(fileName: string): string {
+ if (this._relativeTo)
+ return path.relative(this._relativeTo, fileName);
+ return fileName;
+ }
- static create(context: Context, toolName: string, toolArgs: Record<string, any>) {
- return new Response(++Response._ordinal, context, toolName, toolArgs);
+ async resolveFile(template: FilenameTemplate, title: string): Promise<ResolvedFile> {
+ let fileName: string;
+ if (template.suggestedFilename)
+ fileName = await this._context.outputFile(template.suggestedFilename, { origin: 'llm', title });
+ else
+ fileName = await this._context.outputFile(dateAsFileName(template.prefix, template.ext), { origin: 'code', title });
+ const relativeName = this._computRelativeTo(fileName);
+ const printableLink = `- [${title}](${relativeName})`;
+ return { fileName, relativeName, printableLink };
}
addTextResult(text: string) {
- this._results.push({ title: '', text });
+ this._results.push(text);
}
- addResult(title: string, data: string | Buffer, file: Result['file']) {
- this._results.push({
- text: typeof data === 'string' ? data : undefined,
- data: typeof data === 'string' ? undefined : data,
- title,
- file
- });
+ async addResult(title: string, data: Buffer | string, file: FilenameTemplate) {
+ if (this._context.config.outputMode === 'file' || file.suggestedFilename || typeof data !== 'string') {
+ const resolvedFile = await this.resolveFile(file, title);
+ await this.addFileResult(resolvedFile, data);
+ } else {
+ this.addTextResult(data);
+ }
+ }
+
+ async addFileResult(resolvedFile: ResolvedFile, data: Buffer | string | null) {
+ if (typeof data === 'string')
+ await fs.promises.writeFile(resolvedFile.fileName, data, 'utf-8');
+ else if (data)
+ await fs.promises.writeFile(resolvedFile.fileName, data);
+ this.addTextResult(resolvedFile.printableLink);
+ }
+
+ addFileLink(title: string, fileName: string) {
+ const relativeName = this._computRelativeTo(fileName);
+ this.addTextResult(`- [${title}](${relativeName})`);
+ }
+
+ async registerImageResult(data: Buffer, imageType: 'png' | 'jpeg') {
+ this._imageResults.push({ data, imageType });
}
addError(error: string) {
@@ -101,74 +135,104 @@ export class Response {
this._includeSnapshotFileName = includeSnapshotFileName;
}
- async build(): Promise<Section[]> {
- const rootPath = this._context.firstRootPath();
- const sections: Section[] = [];
- const addSection = (title: string, codeframe?: 'yaml' | 'js') => {
- const section = { title, content: [] as Result[], isError: title === 'Error', codeframe };
- sections.push(section);
- return section.content;
+ async serialize(): Promise<CallToolResult> {
+ const redactText = (text: string): string => {
+ for (const [secretName, secretValue] of Object.entries(this._context.config.secrets ?? {}))
+ text = text.replaceAll(secretValue, `<secret>${secretName}</secret>`);
+ return text;
};
- if (this._errors.length) {
- const content = addSection('Error');
- content.push({ text: this._errors.join('\n'), title: 'error' });
+ const sections = await this._build();
+
+ const text: string[] = [];
+ for (const section of sections) {
+ text.push(`### ${section.title}`);
+ if (section.codeframe)
+ text.push(`\`\`\`${section.codeframe}`);
+ text.push(...section.content);
+ if (section.codeframe)
+ text.push('```');
}
- if (this._results.length) {
- const content = addSection('Result');
- content.push(...this._results);
+ const content: (TextContent | ImageContent)[] = [
+ {
+ type: 'text',
+ text: redactText(text.join('\n')),
+ }
+ ];
+
+ // Image attachments.
+ if (this._context.config.imageResponses !== 'omit') {
+ for (const imageResult of this._imageResults) {
+ const scaledData = scaleImageToFitMessage(imageResult.data, imageResult.imageType);
+ content.push({ type: 'image', data: scaledData.toString('base64'), mimeType: imageResult.imageType === 'png' ? 'image/png' : 'image/jpeg' });
+ }
}
+ return {
+ content,
+ ...(sections.some(section => section.isError) ? { isError: true } : {}),
+ };
+ }
+
+ private async _build(): Promise<Section[]> {
+ const sections: Section[] = [];
+ const addSection = (title: string, content: string[], codeframe?: 'yaml' | 'js') => {
+ const section = { title, content, isError: title === 'Error', codeframe };
+ sections.push(section);
+ return content;
+ };
+
+ if (this._errors.length)
+ addSection('Error', this._errors);
+
+ if (this._results.length)
+ addSection('Result', this._results);
// Code
- if (this._context.config.codegen !== 'none' && this._code.length) {
- const content = addSection('Ran Playwright code', 'js');
- for (const code of this._code)
- content.push({ text: code, title: 'code' });
- }
+ if (this._context.config.codegen !== 'none' && this._code.length)
+ addSection('Ran Playwright code', this._code, 'js');
// Render tab titles upon changes or when more than one tab.
const tabSnapshot = this._context.currentTab() ? await this._context.currentTabOrDie().captureSnapshot() : undefined;
const tabHeaders = await Promise.all(this._context.tabs().map(tab => tab.headerSnapshot()));
if (this._includeSnapshot !== 'none' || tabHeaders.some(header => header.changed)) {
- if (tabHeaders.length !== 1) {
- const content = addSection('Open tabs');
- content.push({ text: renderTabsMarkdown(tabHeaders).join('\n'), title: 'Open tabs' });
- }
-
- const content = addSection('Page');
- content.push({ text: renderTabMarkdown(tabHeaders[0]).join('\n'), title: 'Page' });
+ if (tabHeaders.length !== 1)
+ addSection('Open tabs', renderTabsMarkdown(tabHeaders));
+ addSection('Page', renderTabMarkdown(tabHeaders[0]));
}
// Handle modal states.
- if (tabSnapshot?.modalStates.length) {
- const content = addSection('Modal state');
- content.push({ text: renderModalStates(this._context.config, tabSnapshot.modalStates).join('\n'), title: 'Modal state' });
- }
+ if (tabSnapshot?.modalStates.length)
+ addSection('Modal state', renderModalStates(this._context.config, tabSnapshot.modalStates));
// Handle tab snapshot
if (tabSnapshot && this._includeSnapshot !== 'none') {
- const content = addSection('Snapshot', 'yaml');
const snapshot = this._includeSnapshot === 'full' ? tabSnapshot.ariaSnapshot : tabSnapshot.ariaSnapshotDiff ?? tabSnapshot.ariaSnapshot;
- content.push({ text: snapshot, title: 'snapshot', file: { prefix: 'page', ext: 'yml', suggestedFilename: this._includeSnapshotFileName } });
+ if (this._context.config.outputMode === 'file' || this._includeSnapshotFileName) {
+ const resolvedFile = await this.resolveFile({ prefix: 'page', ext: 'yml', suggestedFilename: this._includeSnapshotFileName }, 'Snapshot');
+ await fs.promises.writeFile(resolvedFile.fileName, snapshot, 'utf-8');
+ addSection('Snapshot', [resolvedFile.printableLink]);
+ } else {
+ addSection('Snapshot', [snapshot], 'yaml');
+ }
}
// Handle tab log
if (tabSnapshot?.events.filter(event => event.type !== 'request').length) {
- const content = addSection('Events');
const text: string[] = [];
for (const event of tabSnapshot.events) {
if (event.type === 'console') {
if (shouldIncludeMessage(this._context.config.console.level, event.message.type))
text.push(`- ${trimMiddle(event.message.toString(), 100)}`);
} else if (event.type === 'download-start') {
+
text.push(`- Downloading file ${event.download.download.suggestedFilename()} ...`);
} else if (event.type === 'download-finish') {
- text.push(`- Downloaded file ${event.download.download.suggestedFilename()} to "${rootPath ? path.relative(rootPath, event.download.outputFile) : event.download.outputFile}"`);
+ text.push(`- Downloaded file ${event.download.download.suggestedFilename()} to "${this._computRelativeTo(event.download.outputFile)}"`);
}
}
- content.push({ text: text.join('\n'), title: 'events' });
+ addSection('Events', text);
}
return sections;
}
@@ -217,61 +281,6 @@ function parseSections(text: string): Map<string, string> {
return sections;
}
-export async function serializeResponse(context: Context, sections: Section[], relativeTo?: string): Promise<CallToolResult> {
- const redactText = (text: string): string => {
- for (const [secretName, secretValue] of Object.entries(context.config.secrets ?? {}))
- text = text.replaceAll(secretValue, `<secret>${secretName}</secret>`);
- return text;
- };
-
- const text: string[] = [];
- for (const section of sections) {
- text.push(`### ${section.title}`);
- const codeframe: string[] = [];
- for (const result of section.content) {
- if (result.file && (result.file.suggestedFilename || context.config.outputMode === 'file' || result.data)) {
- const generatedFileName = await context.outputFile(dateAsFileName(result.file.prefix, result.file.ext), { origin: 'code', title: section.title });
- const fileName = result.file.suggestedFilename ? await context.outputFile(result.file.suggestedFilename, { origin: 'llm', title: section.title }) : generatedFileName;
- text.push(`- [${result.title}](${relativeTo ? path.relative(relativeTo, fileName) : fileName})`);
- if (result.data)
- await fs.promises.writeFile(fileName, result.data, 'utf-8');
- else
- await fs.promises.writeFile(fileName, result.text!);
- } else {
- if (result.text !== undefined)
- codeframe.push(result.text);
- }
- }
-
- if (codeframe?.length) {
- if (section.codeframe)
- text.push(`\`\`\`${section.codeframe}\n${codeframe.join('\n')}\n\`\`\``);
- else
- text.push(codeframe.join('\n'));
- }
- }
-
- const content: (TextContent | ImageContent)[] = [
- {
- type: 'text',
- text: redactText(text.join('\n')),
- }
- ];
-
- // Image attachments.
- if (context.config.imageResponses !== 'omit') {
- for (const result of sections.flatMap(section => section.content).filter(result => result.file?.contentType)) {
- const scaledData = scaleImageToFitMessage(result.data as Buffer, result.file!.contentType === 'image/png' ? 'png' : 'jpeg');
- content.push({ type: 'image', data: scaledData.toString('base64'), mimeType: result.file!.contentType! });
- }
- }
-
- return {
- content,
- ...(sections.some(section => section.isError) ? { isError: true } : {}),
- };
-}
-
export function parseResponse(response: CallToolResult) {
if (response.content?.[0].type !== 'text')
return undefined;
diff --git a/packages/playwright/src/mcp/browser/tools/console.ts b/packages/playwright/src/mcp/browser/tools/console.ts
index f9d3b80fcd..e5e121978c 100644
--- a/packages/playwright/src/mcp/browser/tools/console.ts
+++ b/packages/playwright/src/mcp/browser/tools/console.ts
@@ -32,7 +32,7 @@ const console = defineTabTool({
handle: async (tab, params, response) => {
const messages = await tab.consoleMessages(params.level);
const text = messages.map(message => message.toString()).join('\n');
- response.addResult('Console', text, { prefix: 'console', ext: 'log', suggestedFilename: params.filename });
+ await response.addResult('Console', text, { prefix: 'console', ext: 'log', suggestedFilename: params.filename });
},
});
diff --git a/packages/playwright/src/mcp/browser/tools/network.ts b/packages/playwright/src/mcp/browser/tools/network.ts
index dc16a164e6..4038732e83 100644
--- a/packages/playwright/src/mcp/browser/tools/network.ts
+++ b/packages/playwright/src/mcp/browser/tools/network.ts
@@ -42,7 +42,7 @@ const requests = defineTabTool({
if (rendered)
text.push(rendered);
}
- response.addResult('Network', text.join('\n'), { prefix: 'network', ext: 'log', suggestedFilename: params.filename });
+ await response.addResult('Network', text.join('\n'), { prefix: 'network', ext: 'log', suggestedFilename: params.filename });
},
});
diff --git a/packages/playwright/src/mcp/browser/tools/pdf.ts b/packages/playwright/src/mcp/browser/tools/pdf.ts
index c4b876d785..ce28280742 100644
--- a/packages/playwright/src/mcp/browser/tools/pdf.ts
+++ b/packages/playwright/src/mcp/browser/tools/pdf.ts
@@ -18,7 +18,6 @@ import { z } from 'playwright-core/lib/mcpBundle';
import { formatObject } from 'playwright-core/lib/utils';
import { defineTabTool } from './tool';
-import { dateAsFileName } from './utils';
const pdfSchema = z.object({
filename: z.string().optional().describe('File name to save the pdf to. Defaults to `page-{timestamp}.pdf` if not specified. Prefer relative file names to stay within the output directory.'),
@@ -37,9 +36,9 @@ const pdf = defineTabTool({
handle: async (tab, params, response) => {
const data = await tab.page.pdf();
- const suggestedFilename = params.filename ?? dateAsFileName('page', 'pdf');
- response.addResult('Page as pdf', data, { prefix: 'page', ext: 'pdf', suggestedFilename });
- response.addCode(`await page.pdf(${formatObject({ path: suggestedFilename })});`);
+ const result = await response.resolveFile({ prefix: 'page', ext: 'pdf', suggestedFilename: params.filename }, 'Page as pdf');
+ await response.addFileResult(result, data);
+ response.addCode(`await page.pdf(${formatObject({ path: result.relativeName })});`);
},
});
diff --git a/packages/playwright/src/mcp/browser/tools/screenshot.ts b/packages/playwright/src/mcp/browser/tools/screenshot.ts
index 22f13f12f7..29fdad7d7c 100644
--- a/packages/playwright/src/mcp/browser/tools/screenshot.ts
+++ b/packages/playwright/src/mcp/browser/tools/screenshot.ts
@@ -20,7 +20,6 @@ import { formatObject } from 'playwright-core/lib/utils';
import { z } from 'playwright-core/lib/mcpBundle';
import { defineTabTool } from './tool';
-import { dateAsFileName } from './utils';
import type * as playwright from 'playwright-core';
@@ -56,18 +55,18 @@ const screenshot = defineTabTool({
const screenshotTarget = params.ref ? params.element || 'element' : (params.fullPage ? 'full page' : 'viewport');
const ref = params.ref ? await tab.refLocator({ element: params.element || '', ref: params.ref }) : null;
-
const data = ref ? await ref.locator.screenshot(options) : await tab.page.screenshot(options);
- const suggestedFilename = params.filename || dateAsFileName(ref ? 'element' : 'page', fileType);
- response.addCode(`// Screenshot ${screenshotTarget} and save it as ${suggestedFilename}`);
+ const resolvedFile = await response.resolveFile({ prefix: ref ? 'element' : 'page', ext: fileType, suggestedFilename: params.filename }, `Screenshot of ${screenshotTarget}`);
+
+ response.addCode(`// Screenshot ${screenshotTarget} and save it as ${resolvedFile.relativeName}`);
if (ref)
- response.addCode(`await page.${ref.resolved}.screenshot(${formatObject({ ...options, path: suggestedFilename })});`);
+ response.addCode(`await page.${ref.resolved}.screenshot(${formatObject({ ...options, path: resolvedFile.relativeName })});`);
else
- response.addCode(`await page.screenshot(${formatObject({ ...options, path: suggestedFilename })});`);
+ response.addCode(`await page.screenshot(${formatObject({ ...options, path: resolvedFile.relativeName })});`);
- const contentType = fileType === 'png' ? 'image/png' : 'image/jpeg';
- response.addResult(`Screenshot of ${screenshotTarget}`, data, { prefix: ref ? 'element' : 'page', ext: fileType, suggestedFilename, contentType });
+ await response.addFileResult(resolvedFile, data);
+ await response.registerImageResult(data, fileType);
}
});
diff --git a/packages/playwright/src/mcp/browser/tools/storage.ts b/packages/playwright/src/mcp/browser/tools/storage.ts
index 66591099b1..e83bb231a9 100644
--- a/packages/playwright/src/mcp/browser/tools/storage.ts
+++ b/packages/playwright/src/mcp/browser/tools/storage.ts
@@ -16,7 +16,6 @@
import { z } from 'playwright-core/lib/mcpBundle';
import { defineTool } from './tool';
-import { dateAsFileName } from './utils';
const storageState = defineTool({
capability: 'storage',
@@ -34,10 +33,10 @@ const storageState = defineTool({
handle: async (context, params, response) => {
const browserContext = await context.ensureBrowserContext();
const state = await browserContext.storageState();
- const suggestedFilename = params.filename || dateAsFileName('storage-state', 'json');
const serializedState = JSON.stringify(state, null, 2);
- response.addResult('Storage state', serializedState, { prefix: 'storage-state', ext: 'json', suggestedFilename });
- response.addCode(`await page.context().storageState({ path: '${suggestedFilename}' });`);
+ const resolvedFile = await response.resolveFile({ prefix: 'storage-state', ext: 'json', suggestedFilename: params.filename }, 'Storage state');
+ response.addCode(`await page.context().storageState({ path: '${resolvedFile.relativeName}' });`);
+ await response.addFileResult(resolvedFile, serializedState);
},
});
diff --git a/packages/playwright/src/mcp/browser/tools/tracing.ts b/packages/playwright/src/mcp/browser/tools/tracing.ts
index 6dc4accb35..7c2471076e 100644
--- a/packages/playwright/src/mcp/browser/tools/tracing.ts
+++ b/packages/playwright/src/mcp/browser/tools/tracing.ts
@@ -40,12 +40,11 @@ const tracingStart = defineTool({
snapshots: true,
_live: true,
});
- const traceLegend = `- Action log: ${tracesDir}/${name}.trace
-- Network log: ${tracesDir}/${name}.network
-- Resources with content by sha1: ${tracesDir}/resources`;
-
- response.addTextResult(`Tracing started, saving to ${tracesDir}.\n${traceLegend}`);
- (browserContext.tracing as any)[traceLegendSymbol] = traceLegend;
+ response.addTextResult(`Trace recording started`);
+ response.addFileLink('Action log', `${tracesDir}/${name}.trace`);
+ response.addFileLink('Network log', `${tracesDir}/${name}.network`);
+ response.addFileLink('Resources', `${tracesDir}/resources`);
+ (browserContext.tracing as any)[traceLegendSymbol] = { tracesDir, name };
},
});
@@ -64,7 +63,10 @@ const tracingStop = defineTool({
const browserContext = await context.ensureBrowserContext();
await browserContext.tracing.stop();
const traceLegend = (browserContext.tracing as any)[traceLegendSymbol];
- response.addTextResult(`Tracing stopped.\n${traceLegend}`);
+ response.addTextResult(`Trace recording stopped.`);
+ response.addFileLink('Trace', `${traceLegend.tracesDir}/${traceLegend.name}.trace`);
+ response.addFileLink('Network log', `${traceLegend.tracesDir}/${traceLegend.name}.network`);
+ response.addFileLink('Resources', `${traceLegend.tracesDir}/resources`);
},
});
diff --git a/packages/playwright/src/mcp/browser/tools/video.ts b/packages/playwright/src/mcp/browser/tools/video.ts
index 6474accdf6..4bd777f318 100644
--- a/packages/playwright/src/mcp/browser/tools/video.ts
+++ b/packages/playwright/src/mcp/browser/tools/video.ts
@@ -16,7 +16,6 @@
import { z } from 'playwright-core/lib/mcpBundle';
import { defineTabTool } from './tool';
-import { dateAsFileName } from './utils';
const startVideo = defineTabTool({
capability: 'devtools',
@@ -54,14 +53,9 @@ const stopVideo = defineTabTool({
},
handle: async (tab, params, response) => {
- let videoPath: string | undefined;
- if (params.filename) {
- const suggestedFilename = params.filename ?? dateAsFileName('video', 'webm');
- videoPath = await tab.context.outputFile(suggestedFilename, { origin: 'llm', title: 'Saving video' });
- }
- await tab.page.video().stop({ path: videoPath });
- const tmpPath = await tab.page.video().path();
- response.addTextResult(`Video recording stopped: ${videoPath ?? tmpPath}`);
+ const resolvedFile = await response.resolveFile({ prefix: 'video', ext: 'webm', suggestedFilename: params.filename }, 'Video');
+ await tab.page.video().stop({ path: resolvedFile.fileName });
+ await response.addFileResult(resolvedFile, null);
},
});
diff --git a/packages/playwright/src/mcp/terminal/command.ts b/packages/playwright/src/mcp/terminal/command.ts
index 2800c97aaf..af9dc59f1f 100644
--- a/packages/playwright/src/mcp/terminal/command.ts
+++ b/packages/playwright/src/mcp/terminal/command.ts
@@ -14,8 +14,6 @@
* limitations under the License.
*/
-import path from 'path';
-
import type zodType from 'zod';
export type Category = 'core' | 'navigation' | 'keyboard' | 'mouse' | 'export' | 'storage' | 'tabs' | 'devtools' | 'session' | 'config';
@@ -37,9 +35,6 @@ export function declareCommand<Args extends zodType.ZodTypeAny, Options extends
}
export function parseCommand(command: AnyCommandSchema, args: Record<string, string> & { _: string[] }): { toolName: string, toolParams: any } {
- if (args.filename)
- args.filename = path.resolve(args.outputDir, args.filename);
-
const shape = command.args ? (command.args as zodType.ZodObject<any>).shape : {};
const argv = args['_'];
const options = command.options?.parse({ ...args, _: undefined }) ?? {};
diff --git a/packages/playwright/src/mcp/terminal/program.ts b/packages/playwright/src/mcp/terminal/program.ts
index 97c19a380f..51ec1f3f37 100644
--- a/packages/playwright/src/mcp/terminal/program.ts
+++ b/packages/playwright/src/mcp/terminal/program.ts
@@ -307,7 +307,7 @@ class SessionManager {
this.sessions.set(sessionName, session);
}
- const result = await session.run({ ...args, outputDir });
+ const result = await session.run(args);
console.log(result.text);
session.close();
}
diff --git a/tests/mcp/cli.spec.ts b/tests/mcp/cli.spec.ts
index 4941b540c3..b6601adab5 100644
--- a/tests/mcp/cli.spec.ts
+++ b/tests/mcp/cli.spec.ts
@@ -377,10 +377,10 @@ test.describe('devtools', () => {
test('tracing-start-stop', async ({ cli, server }) => {
await cli('open', server.HELLO_WORLD);
const { output } = await cli('tracing-start');
- expect(output).toContain('Tracing started, saving to');
+ expect(output).toContain('Trace recording started');
await cli('eval', '() => fetch("/hello-world")');
const { output: tracingStopOutput } = await cli('tracing-stop');
- expect(tracingStopOutput).toContain('Tracing stopped.');
+ expect(tracingStopOutput).toContain('Trace recording stopped');
});
test('video-start-stop', async ({ cli, server }) => {
@@ -389,8 +389,7 @@ test.describe('devtools', () => {
expect(videoStartOutput).toContain('Video recording started.');
await cli('open', server.HELLO_WORLD);
const { output: videoStopOutput } = await cli('video-stop', '--filename=video.webm');
- expect(videoStopOutput).toContain('Video recording stopped:');
- expect(videoStopOutput).toContain('.playwright-cli' + path.sep + 'video.webm');
+ expect(videoStopOutput).toContain(`### Result\n- [Video](.playwright-cli${path.sep}video.webm)`);
});
});
diff --git a/tests/mcp/tracing.spec.ts b/tests/mcp/tracing.spec.ts
index 5d8ae0c347..7b63b19993 100644
--- a/tests/mcp/tracing.spec.ts
+++ b/tests/mcp/tracing.spec.ts
@@ -44,7 +44,7 @@ test('check that trace is saved with browser_start_tracing', async ({ startClien
expect(await client.callTool({
name: 'browser_start_tracing',
})).toHaveResponse({
- result: expect.stringContaining(`Tracing started, saving to ${outputDir}`),
+ result: expect.stringContaining(`Trace recording started`),
});
expect(await client.callTool({
@@ -78,7 +78,7 @@ test('check that trace is saved with browser_start_tracing (no output dir)', asy
expect(await client.callTool({
name: 'browser_start_tracing',
})).toHaveResponse({
- result: expect.stringContaining(`Tracing started, saving to ${tmpDir}`),
+ result: expect.stringContaining(`Trace recording started`),
});
expect(await client.callTool({