mirror of
https://github.com/ChromeDevTools/chrome-devtools-mcp.git
synced 2026-11-04 15:00:11 +00:00
feat: add take_memory_snapshot tool (#1023)
Refs: https://github.com/ChromeDevTools/chrome-devtools-mcp/issues/406
This commit is contained in:
1 parent
2cd9b95346
commit
7ffdc5ee4d
5 files changed
+92
-3
No files matched your search
@@ -433,10 +433,11 @@ If you run into any issues, checkout our [troubleshooting guide](./docs/troubles
|
||||
- **Emulation** (2 tools)
|
||||
- [`emulate`](docs/tool-reference.md#emulate)
|
||||
- [`resize_page`](docs/tool-reference.md#resize_page)
|
||||
- **Performance** (3 tools)
|
||||
- **Performance** (4 tools)
|
||||
- [`performance_analyze_insight`](docs/tool-reference.md#performance_analyze_insight)
|
||||
- [`performance_start_trace`](docs/tool-reference.md#performance_start_trace)
|
||||
- [`performance_stop_trace`](docs/tool-reference.md#performance_stop_trace)
|
||||
- [`take_memory_snapshot`](docs/tool-reference.md#take_memory_snapshot)
|
||||
- **Network** (2 tools)
|
||||
- [`get_network_request`](docs/tool-reference.md#get_network_request)
|
||||
- [`list_network_requests`](docs/tool-reference.md#list_network_requests)
|
||||
|
||||
+13
-2
@@ -1,6 +1,6 @@
|
||||
<!-- AUTO GENERATED DO NOT EDIT - run 'npm run docs' to update-->
|
||||
|
||||
# Chrome DevTools MCP Tool Reference (~6719 cl100k_base tokens)
|
||||
# Chrome DevTools MCP Tool Reference (~6885 cl100k_base tokens)
|
||||
|
||||
- **[Input automation](#input-automation)** (8 tools)
|
||||
- [`click`](#click)
|
||||
@@ -21,10 +21,11 @@
|
||||
- **[Emulation](#emulation)** (2 tools)
|
||||
- [`emulate`](#emulate)
|
||||
- [`resize_page`](#resize_page)
|
||||
- **[Performance](#performance)** (3 tools)
|
||||
- **[Performance](#performance)** (4 tools)
|
||||
- [`performance_analyze_insight`](#performance_analyze_insight)
|
||||
- [`performance_start_trace`](#performance_start_trace)
|
||||
- [`performance_stop_trace`](#performance_stop_trace)
|
||||
- [`take_memory_snapshot`](#take_memory_snapshot)
|
||||
- **[Network](#network)** (2 tools)
|
||||
- [`get_network_request`](#get_network_request)
|
||||
- [`list_network_requests`](#list_network_requests)
|
||||
@@ -262,6 +263,16 @@
|
||||
|
||||
---
|
||||
|
||||
### `take_memory_snapshot`
|
||||
|
||||
**Description:** Capture a memory heapsnapshot of the currently selected page to memory leak debugging
|
||||
|
||||
**Parameters:**
|
||||
|
||||
- **filePath** (string) **(required)**: A path to a .heapsnapshot file to save the heapsnapshot to.
|
||||
|
||||
---
|
||||
|
||||
## Network
|
||||
|
||||
### `get_network_request`
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {zod} from '../third_party/index.js';
|
||||
|
||||
import {ToolCategory} from './categories.js';
|
||||
import {defineTool} from './ToolDefinition.js';
|
||||
|
||||
export const takeMemorySnapshot = defineTool({
|
||||
name: 'take_memory_snapshot',
|
||||
description: `Capture a memory heapsnapshot of the currently selected page to memory leak debugging`,
|
||||
annotations: {
|
||||
category: ToolCategory.PERFORMANCE,
|
||||
readOnlyHint: true,
|
||||
},
|
||||
schema: {
|
||||
filePath: zod
|
||||
.string()
|
||||
.describe('A path to a .heapsnapshot file to save the heapsnapshot to.')
|
||||
.endsWith('.heapsnapshot'),
|
||||
},
|
||||
handler: async (request, response, context) => {
|
||||
const page = context.getSelectedPage();
|
||||
|
||||
await page.captureHeapSnapshot({
|
||||
path: request.params.filePath,
|
||||
});
|
||||
|
||||
response.appendResponseLine(
|
||||
`Heap snapshot saved to ${request.params.filePath}`,
|
||||
);
|
||||
},
|
||||
});
|
||||
@@ -8,6 +8,7 @@ import * as consoleTools from './console.js';
|
||||
import * as emulationTools from './emulation.js';
|
||||
import * as extensionTools from './extensions.js';
|
||||
import * as inputTools from './input.js';
|
||||
import * as memoryTools from './memory.js';
|
||||
import * as networkTools from './network.js';
|
||||
import * as pagesTools from './pages.js';
|
||||
import * as performanceTools from './performance.js';
|
||||
@@ -22,6 +23,7 @@ const tools = [
|
||||
...Object.values(emulationTools),
|
||||
...Object.values(extensionTools),
|
||||
...Object.values(inputTools),
|
||||
...Object.values(memoryTools),
|
||||
...Object.values(networkTools),
|
||||
...Object.values(pagesTools),
|
||||
...Object.values(performanceTools),
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2026 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import assert from 'node:assert';
|
||||
import {existsSync} from 'node:fs';
|
||||
import {rm} from 'node:fs/promises';
|
||||
import {tmpdir} from 'node:os';
|
||||
import {join} from 'node:path';
|
||||
import {describe, it} from 'node:test';
|
||||
|
||||
import {takeMemorySnapshot} from '../../src/tools/memory.js';
|
||||
import {withMcpContext} from '../utils.js';
|
||||
|
||||
describe('memory', () => {
|
||||
describe('take_memory_snapshot', () => {
|
||||
it('with default options', async () => {
|
||||
await withMcpContext(async (response, context) => {
|
||||
const filePath = join(tmpdir(), 'test-screenshot.heapsnapshot');
|
||||
try {
|
||||
await takeMemorySnapshot.handler(
|
||||
{params: {filePath}},
|
||||
response,
|
||||
context,
|
||||
);
|
||||
assert.equal(
|
||||
response.responseLines.at(0),
|
||||
`Heap snapshot saved to ${filePath}`,
|
||||
);
|
||||
assert.ok(existsSync(filePath));
|
||||
} finally {
|
||||
await rm(filePath, {force: true});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user