find_in_source
Search page HTML and loaded scripts for a regex pattern, returning file URL, line number, and surrounding context for each match.
Instructions
Search for a regex pattern in page HTML and loaded scripts. Returns matches with file URL, line number, and surrounding context.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pattern | Yes | Regex pattern to search for | |
| contextLines | No | Number of context lines around each match | |
| tabId | No | Target tab ID (defaults to active tab) | |
| apiKey | No | API key for authentication |
Implementation Reference
- src/tools/devtools-sources.ts:94-116 (registration)The 'find_in_source' tool is registered via server.tool() in registerDevtoolsSourcesTools. The registration defines the tool name, description, Zod schema (pattern, contextLines, tabId, apiKey), and the handler function.
server.tool( 'find_in_source', 'Search for a regex pattern in page HTML and loaded scripts. Returns matches with file URL, line number, and surrounding context.', { pattern: z.string().describe('Regex pattern to search for'), contextLines: z.number().optional().default(2).describe('Number of context lines around each match'), tabId: z.number().optional().describe('Target tab ID (defaults to active tab)'), apiKey: z.string().optional().describe('API key for authentication'), }, async ({ pattern, contextLines, tabId, apiKey }) => { const result = await bridge.sendCommand({ command: 'find_in_source', params: { pattern, contextLines }, tabId, apiKey, timeout: LONG_TIMEOUT, }); if (!result.success) { return { content: [{ type: 'text', text: `Error: ${result.error?.message}` }], isError: true }; } return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] }; } ); - src/tools/devtools-sources.ts:103-116 (handler)The handler function for 'find_in_source'. It uses bridge.sendCommand with command: 'find_in_source', passing pattern and contextLines params, plus an extended timeout via LONG_TIMEOUT. The result is returned as JSON.
async ({ pattern, contextLines, tabId, apiKey }) => { const result = await bridge.sendCommand({ command: 'find_in_source', params: { pattern, contextLines }, tabId, apiKey, timeout: LONG_TIMEOUT, }); if (!result.success) { return { content: [{ type: 'text', text: `Error: ${result.error?.message}` }], isError: true }; } return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] }; } ); - src/tools/devtools-sources.ts:97-101 (schema)Zod schema for the 'find_in_source' tool: pattern (string, required), contextLines (number, optional, default 2), tabId (number, optional), apiKey (string, optional).
{ pattern: z.string().describe('Regex pattern to search for'), contextLines: z.number().optional().default(2).describe('Number of context lines around each match'), tabId: z.number().optional().describe('Target tab ID (defaults to active tab)'), apiKey: z.string().optional().describe('API key for authentication'), - src/tools/devtools-sources.ts:91-103 (helper)The handler delegates to WebSocketBridge.sendCommand which sends a WebSocket message to a Chrome extension. The actual source search logic executes in the extension side (not in this codebase).
} ); server.tool( 'find_in_source', 'Search for a regex pattern in page HTML and loaded scripts. Returns matches with file URL, line number, and surrounding context.', { pattern: z.string().describe('Regex pattern to search for'), contextLines: z.number().optional().default(2).describe('Number of context lines around each match'), tabId: z.number().optional().describe('Target tab ID (defaults to active tab)'), apiKey: z.string().optional().describe('API key for authentication'), }, async ({ pattern, contextLines, tabId, apiKey }) => {