getScripts
Extract all JavaScript code from a webpage using Playwright-based browser automation, enabling easy access to scripts for debugging, analysis, or integration purposes.
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 that implements the getScripts tool by extracting all script tags from the current page, including inline scripts and external script 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)Tool schema definition specifying the name, description, and empty input schema (no parameters required).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 dictionary passed to the MCP server capabilities.getScripts: GET_SCRIPTS_TOOL,
- src/server.ts:707-712 (handler)MCP server request handler case that invokes the controller's getScripts method and formats the response for the protocol.case 'getScripts': { const scripts = await playwrightController.getScripts(); return { content: [{ type: "text", text: scripts.join('\n') }] }; }