Navigation
Browser JavaScript Evaluator: Real-Time Testing & Secure Execution - MCP Implementation

Browser JavaScript Evaluator: Real-Time Testing & Secure Execution

Browser JavaScript Evaluator: Run headless browser JS execution via SSE with Claude, enabling real-time code testing on live pages. Secure, scalable server reference design for developers.

Developer Tools
4.4(61 reviews)
91 saves
42 comments

Users create an average of 17 projects per month with this tool

About Browser JavaScript Evaluator

What is Browser JavaScript Evaluator: Real-Time Testing & Secure Execution?

Browser JavaScript Evaluator is a framework enabling secure, real-time execution of JavaScript code within a browser environment, orchestrated via Python using the Model Control Protocol (MCP). This tool bridges server-side logic with browser-based execution, allowing developers to test and validate code dynamically while maintaining strict control over security boundaries. A critical design consideration is the explicit warning that arbitrary code execution poses inherent risks, necessitating cautious deployment in production environments.

How to Use Browser JavaScript Evaluator: Real-Time Testing & Secure Execution?

Integration begins by configuring the MCP server within your development stack. First, specify the server parameters in your application's configuration file to initialize both the MCP server and web server components. Subsequently, establish a browser connection to the local endpoint to enable bidirectional communication. Execution occurs through two primary interfaces: the execute_javascript tool for arbitrary script evaluation and the add_numbers tool for demonstration purposes. All operations follow a synchronous REST API workflow, ensuring deterministic results delivery.

Browser JavaScript Evaluator Features

Key Features of Browser JavaScript Evaluator: Real-Time Testing & Secure Execution?

  • Isolated Execution Environments: Code runs in a sandboxed browser context to prevent unintended side effects.
  • Protocol-Driven Orchestration: MCP coordinates server lifecycle events with granular control over execution triggers.
  • Real-Time Feedback: SSE (Server-Sent Events) enables immediate result propagation without polling overhead.
  • API-First Design: REST endpoints abstract browser interaction, simplifying integration into existing workflows.
  • Modular Architecture: Separation of MCP server and web server components allows independent scaling or modification.

Use Cases of Browser JavaScript Evaluator: Real-Time Testing & Secure Execution?

Primary applications include:

  • Automated cross-browser testing of client-side logic without manual setup
  • Dynamic validation of user-provided JavaScript in secure environments
  • Real-time code execution for low-latency applications requiring browser-native features
  • Security research to analyze code behavior in controlled browser contexts
  • Legacy system integration where server-side execution is insufficient for modern web APIs

Browser JavaScript Evaluator FAQ

FAQ from Browser JavaScript Evaluator: Real-Time Testing & Secure Execution?

  • How is security maintained during execution? The design enforces strict same-origin policy adherence and limits execution scope through browser isolation. Developers must explicitly authorize all code inputs.
  • Does it support multiple browser instances? The current implementation focuses on single-browser control, though the architecture allows scaling through connection pooling in future updates.
  • What happens if execution exceeds time limits? The synchronous API includes configurable timeouts to prevent indefinite blocking, returning controlled error responses.
  • Can this framework execute privileged browser APIs? Yes, but such operations require explicit browser permissions granted during session initialization.
  • How are errors from the browser reported? Execution results include detailed error stacks captured directly from the browser's console output.

Content

Browser JavaScript Evaluator

This project provides a way to execute JavaScript code in a browser from Python using MCP (Model Control Protocol).

⚠️ WARNING ⚠️

This MCP server can execute arbitrary JavaScript in your browser. This can be dangerous. Be aware of the implications of this before using this plugin. Use at your own risk.

Architecture

The project is split into two main components:

  1. Web Server (web_server.py):
* Handles browser connections via Server-Sent Events (SSE)
* Provides a REST API endpoint for executing JavaScript
* Returns results synchronously
  1. MCP Server (mcp_server.py):
* Manages the lifecycle of the web server
* Provides MCP tools for executing JavaScript
* Communicates with the web server via REST API calls

How It Works

  1. The MCP server starts the web server during its lifecycle initialization
  2. A browser connects to the web server via SSE
  3. When an MCP tool is called, it makes a REST API call to the web server
  4. The web server sends the JavaScript code to the browser via SSE
  5. The browser executes the code and sends the result back to the web server
  6. The web server returns the result to the MCP server
  7. The MCP server returns the result to the caller

Usage

Add the MCP server to your Claude config

  ...
  "browser-js-evaluator": {
      "command": "uv",
      "args": [
        "--directory",
        "/path/to/this/repo/mcp_py_sse_browser_control",
        "run",
        "browser_server.py"
      ]
    }
  }
  ...

When you launch Claude Desktop this will start both the MCP server and the web server. Then open a browser and navigate to http://127.0.0.1:8000 to connect to the web server.

Using the MCP Tools

The MCP server provides two tools:

  1. execute_javascript: Execute arbitrary JavaScript code in the browser
  2. add_numbers: Add two numbers together using JavaScript in the browser

These tools can be called from any MCP client.

Development

To run the web server independently (for testing):

python web_server.py

This will start only the web server without the MCP integration.

Related MCP Servers & Clients