chrome-devtools-mcp icon indicating copy to clipboard operation
chrome-devtools-mcp copied to clipboard

Feature Request: Add Save to File for take_snapshot and evaluate_script tools

Open brian-ln opened this issue 3 months ago • 8 comments

Is your feature request related to a problem? Please describe. I am unable to save off screenshots using the chrome-devtools-mcp server. Sometimes I also get too many token errors on tool results.

Describe the solution you'd like Add a save to file optional parameter to tools that return images (take_screenshot) or large amounts of data (take_snapshot, evaluate_script) .

The mcp-chrome server (and several others) supports saving images as files using the asPng optional parameter.

From the mcp-chrome server:

{
    name: TOOL_NAMES.BROWSER.SCREENSHOT,
    description:
      'Take a screenshot of the current page or a specific element(if you want to see the page, recommend to use chrome_get_web_content first)',
    inputSchema: {
      type: 'object',
      properties: {
        name: { type: 'string', description: 'Name for the screenshot, if saving as PNG' },
        selector: { type: 'string', description: 'CSS selector for element to screenshot' },
        width: { type: 'number', description: 'Width in pixels (default: 800)' },
        height: { type: 'number', description: 'Height in pixels (default: 600)' },
        storeBase64: {
          type: 'boolean',
          description:
            'return screenshot in base64 format (default: false) if you want to see the page, recommend set this to be true',
        },
        fullPage: {
          type: 'boolean',
          description: 'Store screenshot of the entire page (default: true)',
        },
        savePng: {
          type: 'boolean',
          description:
            'Save screenshot as PNG file (default: true),if you want to see the page, recommend set this to be false, and set storeBase64 to be true',
        },
      },
      required: [],
    },
  },

Describe alternatives you've considered Claude code can't (or won't) let me save the [Image] data returned from the tool call to take_screenshot...

Additional context The mcp-chrome server (and others) also support returning images as base 64 content using the storeBase64 optional parameter.

brian-ln avatar Sep 25 '25 18:09 brian-ln

I think it makes sense to have this. What we currently do:

  1. if the image is less than 2 MB we return it as an image content according to the MCP.
  2. if it is larger than 2 MB, we save it to a tmp file (automatically generated filename).

Note that the feature request is also about saving script output to file so it only partially overlaps with https://github.com/ChromeDevTools/chrome-devtools-mcp/issues/152.

OrKoN avatar Sep 26 '25 06:09 OrKoN

There is still the open question if its not the MCP client's job to handle such interactions properly.

natorion avatar Sep 26 '25 06:09 natorion

The part about saving screenshots to file was merged but saving script output to file is still to do.

OrKoN avatar Sep 30 '25 17:09 OrKoN

Should we also consider adding the JS file path as an input parameter for evaluate_script? I've found that instead of having the large model temporarily write a lot of repetitive code, it's better to fix the JS file locally and let it be directly read and transferred. This can reduce token consumption.

xubaifuCode avatar Oct 01 '25 03:10 xubaifuCode

Should we also consider adding the JS file path as an input parameter for evaluate_script? I've found that instead of having the large model temporarily write a lot of repetitive code, it's better to fix the JS file locally and let it be directly read and transferred. This can reduce token consumption.

Could you please file a separate feature request for this? and perhaps explain in more details what kind of scripts does your use case require?

OrKoN avatar Oct 01 '25 06:10 OrKoN

I'll take a look at implementing this. Seems straightforward since screenshot already has the filePath pattern.

Coquinate avatar Oct 01 '25 16:10 Coquinate

@Coquinate as suggested by @OrKoN, please create a separate issue first and list a few use cases for this first before working on this.

sebastianbenz avatar Oct 02 '25 09:10 sebastianbenz

@sebastianbenz I believe there may be some confusion - I've worked on the original issue #153 (adding filePath parameter to save evaluate_script and take_snapshot output to file), not the separate suggestion from @xubaifuCode about JS file input.

Issue #153 already documents the use cases:

  • Reducing token consumption when dealing with large script outputs or snapshots
  • Handling data that exceeds MCP size limits

I've already submitted PR #248 with the implementation following the same pattern as take_screenshot's filePath parameter. Happy to discuss the approach or add more context if needed.

Coquinate avatar Oct 02 '25 11:10 Coquinate