Skip to content

fix(mcp): support expressions in browser_evaluate#39979

Merged
yury-s merged 2 commits intomicrosoft:mainfrom
yury-s:fix-296
Apr 1, 2026
Merged

fix(mcp): support expressions in browser_evaluate#39979
yury-s merged 2 commits intomicrosoft:mainfrom
yury-s:fix-296

Conversation

@yury-s
Copy link
Copy Markdown
Member

@yury-s yury-s commented Mar 31, 2026

Summary

  • Replace includes('=>') check with a regex that detects actual function syntax (() =>, x =>, function)
  • This fixes expressions containing => (e.g. [1,2,3].map(x => x*2)) being incorrectly treated as functions

Fixes microsoft/playwright-cli#296

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the MCP browser_evaluate tool to better distinguish between JavaScript functions and expressions, preventing expressions that merely contain => (e.g. inside .map(...)) from being misclassified as functions.

Changes:

  • Replace the naive includes('=>') heuristic with a regex that checks for actual function syntax at the start of the input.
  • Add MCP tests covering expression inputs (including an expression containing an inner arrow function) and function inputs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
tests/mcp/evaluate.spec.ts Adds regression coverage for browser_evaluate handling of expressions vs. functions.
packages/playwright-core/src/tools/backend/evaluate.ts Changes function-vs-expression detection logic used to decide whether to wrap input in () => (...).

Comment thread packages/playwright-core/src/tools/backend/evaluate.ts Outdated
Comment thread tests/mcp/evaluate.spec.ts
Previously, expressions containing `=>` (e.g. `[1,2,3].map(x => x*2)`)
were incorrectly treated as functions and not wrapped. Use a regex to
detect actual function syntax instead.

Fixes: microsoft/playwright-cli#296
@github-actions

This comment has been minimized.

@yury-s yury-s merged commit 9c06959 into microsoft:main Apr 1, 2026
8 of 10 checks passed
@yury-s yury-s deleted the fix-296 branch April 1, 2026 01:02
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 1, 2026

Test results for "MCP"

2 failed
❌ [chrome] › mcp/dashboard.spec.ts:23 › should show browser session chip @mcp-windows-latest
❌ [msedge] › mcp/files.spec.ts:106 › clicking on download link emits download @mcp-windows-latest

6310 passed, 370 skipped


Merge workflow run.

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.

eval with arrow function produces "TypeError: result is not a function"

3 participants