Skip to content

Commit 85b8993

Browse files
authored
feat: support webm format in screencast (#1934)
Modifies the experimental screencast command to support `.webm` in addition to `.mp4`. Renamed `path` to `filePath` to align with other tools.
1 parent b377454 commit 85b8993

3 files changed

Lines changed: 31 additions & 11 deletions

File tree

src/telemetry/tool_call_metrics.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,11 @@
419419
"args": [
420420
{
421421
"name": "path_length",
422+
"argType": "number",
423+
"isDeprecated": true
424+
},
425+
{
426+
"name": "file_path_length",
422427
"argType": "number"
423428
}
424429
]

src/tools/screencast.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import os from 'node:os';
99
import path from 'node:path';
1010

1111
import {zod} from '../third_party/index.js';
12-
import type {ScreenRecorder} from '../third_party/index.js';
12+
import type {ScreenRecorder, VideoFormat} from '../third_party/index.js';
1313
import {ensureExtension} from '../utils/files.js';
1414

1515
import {ToolCategory} from './categories.js';
@@ -20,22 +20,23 @@ async function generateTempFilePath(): Promise<string> {
2020
return path.join(dir, `screencast.mp4`);
2121
}
2222

23+
const supportedExtensions: Array<`.${string}`> = ['.webm', '.mp4'];
24+
2325
export const startScreencast = definePageTool(args => ({
2426
name: 'screencast_start',
25-
description:
26-
'Starts recording a screencast (video) of the selected page in mp4 format.',
27+
description: `Starts recording a screencast (video) of the selected page in specified format.`,
2728
annotations: {
2829
category: ToolCategory.DEBUGGING,
2930
readOnlyHint: false,
3031

3132
conditions: ['screencast'],
3233
},
3334
schema: {
34-
path: zod
35+
filePath: zod
3536
.string()
3637
.optional()
3738
.describe(
38-
'Output path. Uses mkdtemp to generate a unique path if not provided.',
39+
`Output file path (${supportedExtensions.join(',')} are supported). Uses mkdtemp to generate a unique path if not provided.`,
3940
),
4041
},
4142
handler: async (request, response, context) => {
@@ -46,16 +47,30 @@ export const startScreencast = definePageTool(args => ({
4647
return;
4748
}
4849

49-
const filePath = request.params.path ?? (await generateTempFilePath());
50-
const resolvedPath = ensureExtension(path.resolve(filePath), '.mp4');
50+
const filePath = request.params.filePath ?? (await generateTempFilePath());
51+
let enforcedExtension = '.mp4' as `.${string}`;
52+
let format: VideoFormat = 'mp4';
53+
54+
for (const supportedExtension of supportedExtensions) {
55+
if (filePath.endsWith(supportedExtension)) {
56+
enforcedExtension = supportedExtension;
57+
format = supportedExtension.substring(1) as VideoFormat;
58+
break;
59+
}
60+
}
61+
62+
const resolvedPath = ensureExtension(
63+
path.resolve(filePath),
64+
enforcedExtension,
65+
) as `${string}.webm`;
5166

5267
const page = request.page;
5368

5469
let recorder: ScreenRecorder;
5570
try {
5671
recorder = await page.pptrPage.screencast({
57-
path: resolvedPath as `${string}.mp4`,
58-
format: 'mp4' as const,
72+
path: resolvedPath,
73+
format: format,
5974
ffmpegPath: args?.experimentalFfmpegPath,
6075
});
6176
} catch (err) {

tests/tools/screencast.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('screencast', () => {
3535

3636
await startScreencast().handler(
3737
{
38-
params: {path: '/tmp/test-recording.mp4'},
38+
params: {filePath: '/tmp/test-recording.mp4'},
3939
page: context.getSelectedMcpPage(),
4040
},
4141
response,
@@ -113,7 +113,7 @@ describe('screencast', () => {
113113
await assert.rejects(
114114
startScreencast().handler(
115115
{
116-
params: {path: '/tmp/test.mp4'},
116+
params: {filePath: '/tmp/test.mp4'},
117117
page: context.getSelectedMcpPage(),
118118
},
119119
response,

0 commit comments

Comments
 (0)