-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat: add experimental screencast recording tools #941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2025 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import fs from 'node:fs/promises'; | ||
| 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 {ToolCategory} from './categories.js'; | ||
| import type {Context, Response} from './ToolDefinition.js'; | ||
| import {defineTool} from './ToolDefinition.js'; | ||
|
|
||
| async function generateTempFilePath(): Promise<string> { | ||
| const dir = await fs.mkdtemp(path.join(os.tmpdir(), 'chrome-devtools-mcp-')); | ||
| return path.join(dir, `screencast.mp4`); | ||
| } | ||
|
|
||
| export const startScreencast = defineTool({ | ||
| name: 'screencast_start', | ||
| description: | ||
| 'Starts recording a screencast (video) of the selected page in mp4 format. Requires ffmpeg to be installed on the system.', | ||
|
OrKoN marked this conversation as resolved.
Outdated
|
||
| annotations: { | ||
| category: ToolCategory.DEBUGGING, | ||
| readOnlyHint: false, | ||
| conditions: ['screencast'], | ||
| }, | ||
| schema: { | ||
| path: zod | ||
| .string() | ||
| .optional() | ||
| .describe( | ||
| 'Output path. Uses mkdtemp to generate a unique path if not provided.', | ||
| ), | ||
| }, | ||
| handler: async (request, response, context) => { | ||
| if (context.getScreenRecorder() !== null) { | ||
| response.appendResponseLine( | ||
| 'Error: a screencast recording is already in progress. Use screencast_stop to stop it before starting a new one.', | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| const filePath = request.params.path ?? (await generateTempFilePath()); | ||
| const resolvedPath = path.resolve(filePath); | ||
|
|
||
| const page = context.getSelectedPage(); | ||
|
|
||
| let recorder: ScreenRecorder; | ||
| try { | ||
| recorder = await page.screencast({ | ||
| path: resolvedPath as `${string}.mp4`, | ||
| format: 'mp4' as const, | ||
| }); | ||
| } catch (err) { | ||
| const message = err instanceof Error ? err.message : String(err); | ||
| if (message.includes('ENOENT') && message.includes('ffmpeg')) { | ||
| throw new Error( | ||
| 'ffmpeg is required for screencast recording but was not found. ' + | ||
| 'Install ffmpeg (https://ffmpeg.org/) and ensure it is available in your PATH.', | ||
| ); | ||
| } | ||
| throw err; | ||
| } | ||
|
|
||
| context.setScreenRecorder({recorder, filePath: resolvedPath}); | ||
|
|
||
| response.appendResponseLine( | ||
| `Screencast recording started. The recording will be saved to ${resolvedPath}. Use screencast_stop to stop recording.`, | ||
|
OrKoN marked this conversation as resolved.
Outdated
|
||
| ); | ||
| }, | ||
| }); | ||
|
|
||
| export const stopScreencast = defineTool({ | ||
| name: 'screencast_stop', | ||
| description: 'Stops the active screencast recording on the selected page.', | ||
| annotations: { | ||
| category: ToolCategory.DEBUGGING, | ||
| readOnlyHint: false, | ||
| conditions: ['screencast'], | ||
| }, | ||
| schema: {}, | ||
| handler: async (_request, response, context) => { | ||
| await stopScreencastAndAppendOutput(response, context); | ||
| }, | ||
| }); | ||
|
|
||
| async function stopScreencastAndAppendOutput( | ||
| response: Response, | ||
| context: Context, | ||
| ): Promise<void> { | ||
| const data = context.getScreenRecorder(); | ||
| if (!data) { | ||
| return; | ||
| } | ||
| try { | ||
| await data.recorder.stop(); | ||
| response.appendResponseLine( | ||
| `The screencast recording has been stopped and saved to ${data.filePath}.`, | ||
| ); | ||
| } finally { | ||
| context.setScreenRecorder(null); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.