fix(mcp): support expressions in browser_evaluate#39979
Merged
yury-s merged 2 commits intomicrosoft:mainfrom Apr 1, 2026
Merged
fix(mcp): support expressions in browser_evaluate#39979yury-s merged 2 commits intomicrosoft:mainfrom
yury-s merged 2 commits intomicrosoft:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
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 () => (...). |
pavelfeldman
approved these changes
Mar 31, 2026
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
This comment has been minimized.
This comment has been minimized.
Contributor
Test results for "MCP"2 failed 6310 passed, 370 skipped Merge workflow run. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
includes('=>')check with a regex that detects actual function syntax (() =>,x =>,function)=>(e.g.[1,2,3].map(x => x*2)) being incorrectly treated as functionsFixes microsoft/playwright-cli#296