@@ -9,7 +9,7 @@ import os from 'node:os';
99import path from 'node:path' ;
1010
1111import { 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' ;
1313import { ensureExtension } from '../utils/files.js' ;
1414
1515import { 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+
2325export 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 ) {
0 commit comments