Skip to main content
Glama

evaluate

Execute JavaScript code directly on web pages to automate interactions, extract data, or modify content during browser automation sessions.

Instructions

Run JavaScript code on the page

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scriptYesJavaScript code to execute

Implementation Reference

  • Handler function for the 'evaluate' tool. Takes a JavaScript script as input and delegates execution to the browser instance, returning the result in a structured format.
    handler: async ({ script }) => { const result = await browser.evaluate(script); return { success: true, data: { result }, message: 'JavaScript executed successfully' }; }
  • Input schema for the 'evaluate' tool, defining the required 'script' parameter as a string.
    inputSchema: { type: 'object', properties: { script: { type: 'string', description: 'JavaScript code to execute' } }, required: ['script'] },
  • Complete tool object registration for 'evaluate' in the createPlaywrightTools function's return array, including name, description, schema, and handler.
    { name: 'evaluate', description: 'Run JavaScript code on the page', inputSchema: { type: 'object', properties: { script: { type: 'string', description: 'JavaScript code to execute' } }, required: ['script'] }, handler: async ({ script }) => { const result = await browser.evaluate(script); return { success: true, data: { result }, message: 'JavaScript executed successfully' }; } },
  • Supporting 'evaluate' method in SimpleBrowser class that ensures the browser is launched and executes the provided JavaScript on the current page using Playwright's page.evaluate.
    async evaluate(script) { await this.ensureLaunched(); return await this.page.evaluate(script); }

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/zypin-testing/zypin-mcp'

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