You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: MCP browser_run_code_unsafe throws unhandled TypeError when arguments are omitted #44080
constvm=require('vm');constcontext={page: {}};vm.createContext(context);letcode=undefined;context.__fn__=vm.runInContext('('+code+')',context);// returns undefinedawaitcontext.__fn__(context.page);// throws TypeError: context.__fn__ is not a function
Expected behavior
The tool should validate arguments and return a clean error: Error: At least one of "code" or "filename" must be provided.
This matches the input validation pattern used in browser_drop and browser_find.
Actual behavior
The tool crashes with an internal VM TypeError:
### Error
TypeError: __fn__ is not a function
Additional context
In packages/playwright-core/src/tools/backend/runCode.ts:
Both code and filename are optional in the Zod schema (codeSchema).
This evaluates (undefined) and sets context.__fn__ to undefined.
The IIFE then executes:
constresult=await__fn__(page);
This throws TypeError: __fn__ is not a function.
Proposed fix:
Add validation in packages/playwright-core/src/tools/backend/runCode.ts:
if(!params.code&&!params.filename)thrownewError('At least one of "code" or "filename" must be provided.');
I have verified the reproduction and the fix locally with tests in tests/mcp/run-code.spec.ts.
I would like to work on this issue and submit a pull request once approved. Please assign this issue to me.
I have reproduced this issue locally and have a fix with regression tests ready. Please assign this issue to me, and I will submit the pull request. Thank you!
Hi, I'm the Playwright bot and I reproduced this on Linux.
Reproduced on Chromium, Firefox, and WebKit with 1.66.0-next, commit 8882d1c85ef808500d99a2e28778e544c8a77fef. Missing arguments reach the VM as (undefined), then the handler tries to call that value. The TypeError is returned as a tool error, rather than crashing the server.
The proposed fix rejects calls with neither code nor filename with the requested message, following the existing browser_drop validation pattern.
Reproduction and checks
The existing browser_run_code_unsafe test now includes:
expect(awaitclient.callTool({name: 'browser_run_code_unsafe',arguments: {},})).toHaveResponse({error: 'Error: At least one of "code" or "filename" must be provided.',isError: true,});
Before the fix, this assertion returned TypeError: __fn__ is not a function on all three browsers in headless mode. Node 24.22.2; Linux. The reported version is main, so no older release was required. macOS was not tested.
With the fix, all 57 tests in run-code.spec.ts and evaluate.spec.ts passed across Chromium, Firefox, and WebKit: npm run test-mcp -- run-code.spec.ts evaluate.spec.ts --project=chromium --project=firefox --project=webkit --workers=2. This includes normal code execution, file loading, and calls after an error. npm run build and npm run flint also passed.
Activity
halcyon-past commentedon Nov 12, 2026
I have reproduced this issue locally and have a fix with regression tests ready. Please assign this issue to me, and I will submit the pull request. Thank you!
microsoft-playwright-automation commentedon Nov 12, 2026
microsoft-playwright-automation commentedon Nov 12, 2026
Hi, I'm the Playwright bot and I reproduced this on Linux.
Reproduced on Chromium, Firefox, and WebKit with
1.66.0-next, commit8882d1c85ef808500d99a2e28778e544c8a77fef. Missing arguments reach the VM as(undefined), then the handler tries to call that value. The TypeError is returned as a tool error, rather than crashing the server.The proposed fix rejects calls with neither code nor filename with the requested message, following the existing
browser_dropvalidation pattern.Reproduction and checks
The existing
browser_run_code_unsafetest now includes:Before the fix, this assertion returned
TypeError: __fn__ is not a functionon all three browsers in headless mode. Node24.22.2; Linux. The reported version is main, so no older release was required. macOS was not tested.Command:
npm run test-mcp -- run-code.spec.ts --project=chromium --project=firefox --project=webkit --grep 'browser_run_code_unsafe$' --workers=1.With the fix, all 57 tests in
run-code.spec.tsandevaluate.spec.tspassed across Chromium, Firefox, and WebKit:npm run test-mcp -- run-code.spec.ts evaluate.spec.ts --project=chromium --project=firefox --project=webkit --workers=2. This includes normal code execution, file loading, and calls after an error.npm run buildandnpm run flintalso passed.Draft PR: #44087
Triaged on Linux by the Playwright bot - agent run
chore: mark v0.0.86 (#1873)
chore: mark v0.1.25 (#546)
chore(deps): update all non-major dependencies (#383)
chore(deps): update dependency @playwright/mcp to v0.0.86 (#3298)
chore(deps): update dependency npm:@playwright/mcp to v0.0.86 (#25)