Skip to content

Commit dd9971e

Browse files
dprevoznikclaude
andcommitted
Remove per-call replay recording from execute_playwright_code
Each execute_playwright_code call wrapped the run in replays.start / replays.stop and validated existing sessions with a browsers.retrieve, adding three round trips around the one useful call. In a tight agent loop that latency lands on the critical path every turn. Drop the replay start/stop and the pre-execute retrieve; execute surfaces a not-found error on its own. Existing-session calls now make a single round trip. Video replay is handled separately via managed replay controls. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 2258ad4 commit dd9971e

2 files changed

Lines changed: 14 additions & 47 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ The Kernel MCP Server bridges AI assistants (like Claude, Cursor, or other MCP-c
2020
- 📊 Monitor deployments and track invocations
2121
- 🔍 Search Kernel documentation and inject context
2222
- 💻 Execute arbitrary Playwright code against live browsers
23-
- 🎥 Automatically record video replays of browser automation
23+
- 🎥 Record video replays of browser automation
2424

2525
**Open-source & fully-managed** — the complete codebase is available here, and we run the production instance so you don't need to deploy anything.
2626

@@ -279,7 +279,7 @@ Self-hosted deployments can hide sensitive tool families by setting `KERNEL_MCP_
279279

280280
- `computer_action` - Mouse, keyboard, clipboard, and screenshot controls for browser sessions (click, type, press_key, scroll, move, get_position, read_clipboard, write_clipboard, screenshot).
281281
- `browser_curl` - Send HTTP requests through an existing browser session's Chrome network stack.
282-
- `execute_playwright_code` - Execute Playwright/TypeScript code against a browser with automatic video replay and cleanup.
282+
- `execute_playwright_code` - Execute Playwright/TypeScript code against a browser, with automatic cleanup of browsers it creates.
283283
- `exec_command` - Run shell commands inside a browser VM. Returns decoded stdout/stderr.
284284
- `search_docs` - Search Kernel platform documentation and guides.
285285

@@ -322,7 +322,7 @@ Assistant: I'll execute your web-scraper action with reddit.com as the target.
322322
Human: Go to example.com and get me the page title
323323
Assistant: I'll execute Playwright code to navigate to the site and retrieve the title.
324324
[Uses execute_playwright_code tool with code: "await page.goto('https://example.com'); return await page.title();"]
325-
Returns: { success: true, result: "Example Domain", replay_url: "https://..." }
325+
Returns: { success: true, result: "Example Domain" }
326326
```
327327

328328
### Set up browser profiles for authentication

‎src/lib/mcp/tools/playwright.ts‎

Lines changed: 11 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export function registerPlaywrightTool(server: McpServer) {
66
// execute_playwright_code -- Run Playwright/TypeScript code against a browser
77
server.tool(
88
"execute_playwright_code",
9-
'Execute Playwright/TypeScript automation code against a Kernel browser session. If session_id is provided, uses that existing browser; otherwise creates a new one. Returns the result with a video replay URL. Auto-cleans up browsers it creates. Use computer_action with action "screenshot" instead of page.screenshot() in code.',
9+
'Execute Playwright/TypeScript automation code against a Kernel browser session. If session_id is provided, uses that existing browser; otherwise creates a new one. Auto-cleans up browsers it creates. Use computer_action with action "screenshot" instead of page.screenshot() in code.',
1010
{
1111
code: z
1212
.string()
@@ -30,49 +30,27 @@ export function registerPlaywrightTool(server: McpServer) {
3030
async ({ code, session_id }, extra) => {
3131
if (!extra.authInfo) throw new Error("Authentication required");
3232
const client = createKernelClient(extra.authInfo.token);
33-
let kernelBrowser;
34-
let replay;
3533
const shouldCleanup = !session_id;
34+
let activeSessionId = session_id;
3635

3736
try {
3837
if (!code || typeof code !== "string")
3938
throw new Error("code is required and must be a string");
4039

41-
if (session_id) {
42-
kernelBrowser = await client.browsers.retrieve(session_id);
43-
if (!kernelBrowser)
44-
throw new Error(`Browser session "${session_id}" not found`);
45-
} else {
46-
kernelBrowser = await client.browsers.create({ stealth: true });
47-
if (!kernelBrowser?.session_id)
40+
if (!activeSessionId) {
41+
const created = await client.browsers.create({ stealth: true });
42+
if (!created?.session_id)
4843
throw new Error("Failed to create browser session");
49-
}
50-
51-
try {
52-
replay = await client.browsers.replays.start(
53-
kernelBrowser.session_id,
54-
);
55-
} catch {
56-
replay = null;
44+
activeSessionId = created.session_id;
5745
}
5846

5947
const response = await client.browsers.playwright.execute(
60-
kernelBrowser.session_id,
48+
activeSessionId,
6149
{ code },
6250
);
6351

64-
let replayUrl = null;
65-
if (replay && kernelBrowser?.session_id) {
66-
try {
67-
await client.browsers.replays.stop(replay.replay_id, {
68-
id: kernelBrowser.session_id,
69-
});
70-
replayUrl = replay.replay_view_url;
71-
} catch {}
72-
}
73-
74-
if (shouldCleanup && kernelBrowser?.session_id) {
75-
await client.browsers.deleteByID(kernelBrowser.session_id);
52+
if (shouldCleanup) {
53+
await client.browsers.deleteByID(activeSessionId);
7654
}
7755

7856
return {
@@ -86,7 +64,6 @@ export function registerPlaywrightTool(server: McpServer) {
8664
error: response.error,
8765
stdout: response.stdout,
8866
stderr: response.stderr,
89-
replay_url: replayUrl,
9067
},
9168
null,
9269
2,
@@ -95,18 +72,9 @@ export function registerPlaywrightTool(server: McpServer) {
9572
],
9673
};
9774
} catch (error) {
98-
let replayUrl = null;
99-
if (replay && kernelBrowser?.session_id) {
100-
try {
101-
await client.browsers.replays.stop(replay.replay_id, {
102-
id: kernelBrowser.session_id,
103-
});
104-
replayUrl = replay.replay_view_url;
105-
} catch {}
106-
}
10775
try {
108-
if (shouldCleanup && kernelBrowser?.session_id)
109-
await client.browsers.deleteByID(kernelBrowser.session_id);
76+
if (shouldCleanup && activeSessionId)
77+
await client.browsers.deleteByID(activeSessionId);
11078
} catch {}
11179

11280
return {
@@ -117,7 +85,6 @@ export function registerPlaywrightTool(server: McpServer) {
11785
{
11886
success: false,
11987
error: error instanceof Error ? error.message : String(error),
120-
replay_url: replayUrl,
12188
},
12289
null,
12390
2,

0 commit comments

Comments
 (0)