Skip to content

take_screenshot captures white background instead of CSS background for transparent canvas elements #806

Description

@drlamer

Problem

When using take_screenshot on pages with transparent <canvas> elements (e.g., Cytoscape.js, Chart.js, Three.js), the screenshot shows a white background instead of the actual CSS background color set on the container element.

Root Cause

The Chrome DevTools Protocol Page.captureScreenshot composites transparent layers against a white base layer by default, ignoring CSS backgrounds behind transparent elements.

Evidence

// DOM inspection shows correct setup:
containerBgColor: "rgb(15, 23, 42)"  // Dark slate - correct
canvasPixels: { r: 0, g: 0, b: 0, a: 0 }  // Transparent - expected

// But screenshot shows WHITE where it should be dark
  • User's browser renders correctly (dark background visible)
  • MCP screenshot shows white background
  • Same page, same DOM, different visual result

Expected Behavior

Screenshots should capture what the user actually sees in the browser, including CSS backgrounds behind transparent canvas elements.

Suggested Fix

Call Emulation.setDefaultBackgroundColorOverride before Page.captureScreenshot:

// Option 1: Add parameter to take_screenshot
take_screenshot({ backgroundColor: { r: 15, g: 23, b: 42, a: 255 } })

// Option 2: Auto-detect from page's computed background
const bgColor = await getComputedBackgroundColor();
await cdp.send('Emulation.setDefaultBackgroundColorOverride', { color: bgColor });
await cdp.send('Page.captureScreenshot', {...});
await cdp.send('Emulation.setDefaultBackgroundColorOverride', {}); // Reset

Affected Use Cases

  • Network topology visualizations (Cytoscape.js)
  • Data visualization dashboards (Chart.js, D3.js)
  • 3D scenes (Three.js, Babylon.js)
  • Any app using transparent canvas overlays with CSS backgrounds
  • Dark mode applications with canvas elements

Environment

  • chrome-devtools-mcp: latest (via npx)
  • Chrome: 143.x
  • OS: Windows 10

References

Activity

  1. added theissue type on Jan 21, 2026
  2. changed the issue type fromtoon Oct 14, 2026
  3. changed the issue type fromtoon Oct 21, 2026
  4. OrKoN commented on Oct 21, 2026

    @OrKoN
    Collaborator

    This is rather a feature. We currently do not attempt to determine actual background colors for web content and it is not always clear how it should work. Probably we should start by extending emulate command with background color.

  5. OrKoN commented on Nov 26, 2026

    @OrKoN
    Collaborator

    I believe this is solved by #3457

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions