Skip to content

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

chore: do not rename video files outside --save-videos (#37616)

Pavel Feldman2d33cddd4409
diff --git a/packages/playwright/src/mcp/browser/context.ts b/packages/playwright/src/mcp/browser/context.ts
index 80eadfda1c..79f2bae3a5 100644
--- a/packages/playwright/src/mcp/browser/context.ts
+++ b/packages/playwright/src/mcp/browser/context.ts
@@ -167,7 +167,7 @@ export class Context {
await promise.then(async ({ browserContext, close }) => {
if (this.config.saveTrace)
await browserContext.tracing.stop();
- const videos = browserContext.pages().map(page => page.video()).filter(video => !!video);
+ const videos = this.config.saveVideo ? browserContext.pages().map(page => page.video()).filter(video => !!video) : [];
await close(async () => {
for (const video of videos) {
const name = await this.outputFile(dateAsFileName('webm'), { origin: 'code', reason: 'Saving video' });
diff --git a/tests/mcp/video.spec.ts b/tests/mcp/video.spec.ts
index 13c5f1898f..90231fe398 100644
--- a/tests/mcp/video.spec.ts
+++ b/tests/mcp/video.spec.ts
@@ -43,6 +43,42 @@ for (const mode of ['isolated', 'persistent']) {
});
const [file] = await fs.promises.readdir(outputDir);
- expect(file).toMatch(/page-.*.webm/);
+ expect(file).toMatch(/page-.*\.webm/);
+ });
+
+ test(`should work with recordVideo (${mode})`, async ({ startClient, server }, testInfo) => {
+ const videosDir = testInfo.outputPath('videos');
+
+ const { client } = await startClient({
+ config: {
+ browser: {
+ contextOptions: {
+ recordVideo: {
+ dir: videosDir,
+ size: { width: 800, height: 600 },
+ },
+ }
+ }
+ },
+ args: [
+ ...(mode === 'isolated' ? ['--isolated'] : []),
+ ],
+ });
+
+ expect(await client.callTool({
+ name: 'browser_navigate',
+ arguments: { url: server.HELLO_WORLD },
+ })).toHaveResponse({
+ code: expect.stringContaining(`page.goto('http://localhost`),
+ });
+
+ expect(await client.callTool({
+ name: 'browser_close',
+ })).toHaveResponse({
+ code: expect.stringContaining(`page.close()`),
+ });
+
+ const [file] = await fs.promises.readdir(videosDir);
+ expect(file).toMatch(/.*.\webm/);
});
}