Skip to content

[MCP]: browser_file_upload emits invalid code and does not cancel file chooser when paths is omitted #44091

Closed

Description

What's going on?

The schema description for browser_file_upload states:

If omitted, file chooser is cancelled.

However, when browser_file_upload is invoked without paths (or with paths: undefined):

  1. The tool emits invalid generated code await fileChooser.setFiles(undefined) instead of await fileChooser.setFiles([]).
  2. The file chooser is not cancelled on the page because the invocation of modalState.fileChooser.setFiles is skipped when paths is undefined.

Steps to reproduce

  1. Open a page with <input type="file" />.
  2. Trigger the file chooser via browser_click.
  3. Call browser_file_upload with {} (omitting paths).

Actual behavior

  • Tool emits await fileChooser.setFiles(undefined).
  • modalState.fileChooser.setFiles([]) is never called, leaving the browser file chooser unhandled on the page.

Expected behavior

  • Tool emits await fileChooser.setFiles([]).
  • modalState.fileChooser.setFiles([]) is called to cancel the file chooser.

I have investigated the root cause and prepared a local fix with regression tests. Please assign this issue to me so I can submit the pull request.

Version

1.51.0 (main)

Activity

  1. halcyon-past commented on Nov 13, 2026

    @halcyon-past
    ContributorAuthor

    I have submitted a pull request with the fix and regression coverage in #44092.

  2. Johanl001 commented on Nov 13, 2026

    @Johanl001

    Hi, I'd like to work on this issue. Could you please assign it to me? I'm interested in contributing and will work on implementing a solution. Thanks!

  3. microsoft-playwright-automation commented on Nov 13, 2026

    @microsoft-playwright-automation
  4. microsoft-playwright-automation commented on Nov 13, 2026

    @microsoft-playwright-automation
    Contributor

    Hi, I'm the Playwright bot. I reproduced this and checked #44092.

    Reproduced on main; fixed by #44092 at fd8a561f6c4bbe49ff65754ce39ffc69691607ff. Chromium, Firefox and WebKit behave the same on Linux. Omitting paths generates setFiles(undefined) and skips the actual setFiles call. The PR supplies [] and always calls setFiles, fixing both parts.

    Reproduction and results

    On main, version 1.66.0-next, commit 8534271f0413bae6a455b7cf43b2637391bc614b:

    server.setContent('/', '<input type="file" />', 'text/html');
    await client.callTool({
      name: 'browser_navigate',
      arguments: { url: server.PREFIX },
    });
    await client.callTool({
      name: 'browser_click',
      arguments: { element: 'File input', target: 'e2' },
    });
    expect(await client.callTool({
      name: 'browser_file_upload',
      arguments: {},
    })).toHaveResponse({
      code: 'await fileChooser.setFiles([])',
      modalState: undefined,
    });

    The generated code is instead await fileChooser.setFiles(undefined).

    I also extended the existing upload test independently: upload a file, reopen the chooser, call the tool with {}, then check input.files.length and the generated code. On main, the file count stays at 1; on the PR, it becomes 0 and the code uses setFiles([]).

    Check Chromium Firefox WebKit
    Independent regression on main Fails as reported Fails as reported Fails as reported
    PR regression with main's implementation Fails as reported Fails as reported Fails as reported
    Independent regression on the PR Passes Passes Passes
    PR's upload regression Passes Passes Passes
    Checks run

    All browser runs were headless on Linux:

    npm run test-mcp -- files.spec.ts --project=chromium --project=firefox --project=webkit --grep 'browser_file_upload$'
    npm run test-mcp -- files.spec.ts file-paths.spec.ts dialogs.spec.ts --project=chromium --project=firefox --project=webkit --workers=2
    npm run build
    npm run flint

    The broader test run passed 65 tests, with 4 existing skips. Build and all lint checks passed. WebKit initially needed system libraries; after installing them, its tests ran successfully. The PR remains open, is not a draft, and has no merge conflicts. Its CLA check passed; no browser CI jobs have run on the fork PR. No second fix is proposed.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions