getScripts
Extract all JavaScript code from web pages to analyze scripts, debug issues, or collect code snippets for automation tasks.
Instructions
Get all JavaScript code from the current page
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/controllers/playwright.ts:323-344 (handler)Core handler function in PlaywrightController that extracts all script content from the current page by evaluating JavaScript to query script tags, handling both inline scripts and external src URLs.async getScripts(): Promise<string[]> { try { if (!this.isInitialized()) { throw new Error('Browser not initialized'); } this.log('Getting page scripts'); const scripts = await this.state.page?.evaluate(() => { const scriptElements = Array.from(document.querySelectorAll('script')); return scriptElements.map(script => { if (script.src) { return `// External script: ${script.src}`; } return script.textContent || script.innerHTML; }).filter(content => content.trim().length > 0); }); this.log('Scripts retrieved:', scripts?.length); return scripts || []; } catch (error: any) { console.error('Get scripts error:', error); throw new BrowserError('Failed to get scripts', 'Check if the page is loaded'); } }
- src/server.ts:123-131 (schema)MCP Tool schema definition for getScripts, specifying name, description, and input schema (no required parameters).const GET_SCRIPTS_TOOL: Tool = { name: "getScripts", description: "Get all JavaScript code from the current page", inputSchema: { type: "object", properties: {}, required: [] } };
- src/server.ts:526-526 (registration)Registration of the getScripts tool in the tools object provided to the MCP server's capabilities.getScripts: GET_SCRIPTS_TOOL,
- src/server.ts:707-712 (handler)MCP server request handler case for 'getScripts' that delegates to PlaywrightController.getScripts() and formats the response as MCP content.case 'getScripts': { const scripts = await playwrightController.getScripts(); return { content: [{ type: "text", text: scripts.join('\n') }] }; }