Skip to main content
Glama
jomon003

PlayMCP Browser Automation Server

by jomon003

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
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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'); } }
  • 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,
  • 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') }] }; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jomon003/PlayMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server