Skip to main content
Glama
jomon003

PlayMCP Browser Automation Server

by jomon003

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
NameRequiredDescriptionDefault

No arguments

Implementation Reference

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

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