Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/telemetry/tool_call_metrics.json
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,11 @@
"args": [
{
"name": "path_length",
"argType": "number",
"isDeprecated": true
},
{
"name": "file_path_length",
"argType": "number"
}
]
Expand Down
33 changes: 24 additions & 9 deletions src/tools/screencast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import os from 'node:os';
import path from 'node:path';

import {zod} from '../third_party/index.js';
import type {ScreenRecorder} from '../third_party/index.js';
import type {ScreenRecorder, VideoFormat} from '../third_party/index.js';
import {ensureExtension} from '../utils/files.js';

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

const supportedExtensions: Array<`.${string}`> = ['.webm', '.mp4'];

export const startScreencast = definePageTool(args => ({
name: 'screencast_start',
description:
'Starts recording a screencast (video) of the selected page in mp4 format.',
description: `Starts recording a screencast (video) of the selected page in specified format.`,
annotations: {
category: ToolCategory.DEBUGGING,
readOnlyHint: false,

conditions: ['screencast'],
},
schema: {
path: zod
filePath: zod
.string()
.optional()
.describe(
'Output path. Uses mkdtemp to generate a unique path if not provided.',
`Output file path (${supportedExtensions.join(',')} are supported). Uses mkdtemp to generate a unique path if not provided.`,
),
},
handler: async (request, response, context) => {
Expand All @@ -46,16 +47,30 @@ export const startScreencast = definePageTool(args => ({
return;
}

const filePath = request.params.path ?? (await generateTempFilePath());
const resolvedPath = ensureExtension(path.resolve(filePath), '.mp4');
const filePath = request.params.filePath ?? (await generateTempFilePath());
let enforcedExtension = '.mp4' as `.${string}`;
Comment thread
OrKoN marked this conversation as resolved.
let format: VideoFormat = 'mp4';

for (const supportedExtension of supportedExtensions) {
if (filePath.endsWith(supportedExtension)) {
enforcedExtension = supportedExtension;
format = supportedExtension.substring(1) as VideoFormat;
break;
}
}

const resolvedPath = ensureExtension(
path.resolve(filePath),
enforcedExtension,
) as `${string}.webm`;
Comment thread
OrKoN marked this conversation as resolved.

const page = request.page;

let recorder: ScreenRecorder;
try {
recorder = await page.pptrPage.screencast({
path: resolvedPath as `${string}.mp4`,
format: 'mp4' as const,
path: resolvedPath,
format: format,
ffmpegPath: args?.experimentalFfmpegPath,
});
} catch (err) {
Expand Down
4 changes: 2 additions & 2 deletions tests/tools/screencast.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('screencast', () => {

await startScreencast().handler(
{
params: {path: '/tmp/test-recording.mp4'},
params: {filePath: '/tmp/test-recording.mp4'},
page: context.getSelectedMcpPage(),
},
response,
Expand Down Expand Up @@ -113,7 +113,7 @@ describe('screencast', () => {
await assert.rejects(
startScreencast().handler(
{
params: {path: '/tmp/test.mp4'},
params: {filePath: '/tmp/test.mp4'},
page: context.getSelectedMcpPage(),
},
response,
Expand Down
Loading