Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add browser_evaluate tool for JavaScript execution#60

Merged
hugs merged 7 commits intoVibiumDev:mainfrom
jolks:add-browser-evaluate
Feb 8, 2026
Merged

Add browser_evaluate tool for JavaScript execution#60
hugs merged 7 commits intoVibiumDev:mainfrom
jolks:add-browser-evaluate

Conversation

@jolks
Copy link
Contributor

@jolks jolks commented Jan 27, 2026

Summary

This PR adds a new MCP tool browser_evaluate that allows executing JavaScript code in the browser and returning the result. Also adds evaluate() method to the Python client for feature parity with the JavaScript client.

Changes

MCP Server (Go):

  • Add browser_evaluate tool schema in mcp/schema.go
  • Implement browserEvaluate handler in mcp/handlers.go
  • Update tests to expect 8 tools instead of 7
  • Add test for browser_evaluate functionality

Python Client:

  • Add evaluate() method to Vibe class (async API)
  • Add evaluate() method to VibeSync class (sync API)
  • Add comprehensive tests for JavaScript evaluation

JavaScript Client:

  • No changes needed - evaluate() method already exists (clients/javascript/src/vibe.ts:68-82)

Implementation

The MCP tool uses the existing Evaluate() method from the BiDi client, making this a small addition (~50 lines) that exposes existing functionality.

The Python client implementation mirrors the JavaScript client's evaluate() method, using the script.evaluate BiDi protocol method.

Context

The underlying Go BiDi client has always had an Evaluate() method, and the JavaScript client has had evaluate() since its initial implementation. This PR:

  1. Exposes that functionality to AI agents via the new MCP browser_evaluate tool
  2. Adds the missing evaluate() method to the Python client for feature parity

Use Cases

  • Extract HTML content from page elements (e.g., document.querySelector('#container').outerHTML)
  • Inspect DOM state
  • Run custom JavaScript for automation tasks
  • Get computed values from the page (e.g., document.title, window.location.href)

Testing

MCP Server Tests:

  • ✅ Test that tools/list returns 8 tools including browser_evaluate
  • ✅ Test that browser_evaluate executes JavaScript and returns results
node tests/mcp/server.test.js
# tests 13
# pass 13
# fail 0

Python Client Tests:

  • ✅ Test evaluate with string expressions (document.title)
  • ✅ Test evaluate with numeric expressions (2 + 2)
  • ✅ Test evaluate with object property access (window.location.href)
make test-python
# Python client test passed!

Feature Parity

All three interfaces now support JavaScript evaluation:

  • ✅ MCP Server (browser_evaluate tool) - NEW
  • ✅ JavaScript Client (vibe.evaluate() method) - already existed
  • ✅ Python Client (vibe.evaluate() method) - NEW

Related

This enables use cases like extracting structured data from web pages without relying solely on CSS selectors, which was the motivation for this addition.

hugs and others added 7 commits January 18, 2026 19:57
Add --disable-notifications flag and set notifications content setting
to block, preventing the "Google Chrome for Testing Notifications"
dialog from appearing on first launch.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
This adds a new MCP tool `browser_evaluate` that allows executing
JavaScript code in the browser and returning the result.

Changes:
- Add browser_evaluate tool schema in mcp/schema.go
- Implement browserEvaluate handler in mcp/handlers.go
- Update tests to expect 8 tools instead of 7
- Add test for browser_evaluate functionality

The tool uses the existing Evaluate() method from the BiDi client,
making this a small addition that exposes existing functionality.

Use case: Extract HTML content from page elements, inspect DOM
state, or run custom JavaScript for automation tasks.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Makes it clear that browser_evaluate is the primary tool for extracting
data from pages, not just executing arbitrary JavaScript.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Update MCP tools documentation to include the browser_evaluate tool
added in PR VibiumDev#60. This tool executes JavaScript in the browser to
extract data, query the DOM, or inspect page state.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Implement feature parity with JavaScript client and MCP server by adding
evaluate() method to execute JavaScript in the page context.

Changes:
- Add async evaluate() method to Vibe class
- Add sync evaluate() method to VibeSync class
- Add comprehensive tests for string, numeric, and object evaluations
- Use script.evaluate BiDi protocol method

All Python client tests pass.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Add browser_evaluate to MCP tools table and showcase the new evaluate()
method in all client examples (JavaScript and Python, both sync and async).

Changes:
- Add browser_evaluate to MCP server tools table
- Add evaluate() examples to JS sync and async code samples
- Add evaluate() examples to Python sync and async code samples

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
@hugs hugs merged commit 301acee into VibiumDev:main Feb 8, 2026
@hugs
Copy link
Contributor

hugs commented Feb 8, 2026

merged. thank you, @jolks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants