New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.
Starred by 9 users

Issue metadata

Status: Fixed
Closed: May 2017
EstimatedDays: ----
NextAction: ----
OS: Windows , Mac
Pri: 2
Type: Bug

Sign in to add a comment

Page.captureScreenshot() fails when running --headless

Reported by, Apr 21 2017

Issue description

UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36

Steps to reproduce the problem:
1. Run Chromium with --headless flag
2. Use "chrome-remote-interface" (nodejs module) to capture page screenshot (Page.captureScreenshot()), or follow the steps described on to capture a screenshot

What is the expected behavior?
Screenshot is created, callback is called (when using chrome-remote-interface).

What went wrong?
Exception occurs:

Chrome stderr [0421/] Failed to print window: Invalid window handle. (0x578)
Chrome stderr [0421/] NOT IMPLEMENTED

Did this work before? N/A 

Does this work in other browsers? N/A

Chrome version: 60.0.3078.0  Channel: dev
OS Version: 10.0
Flash Version:
Please assign "Proj=Headless" to this issue.
Labels: Needs-Triage-M60

Comment 3 by, Apr 25 2017

Labels: TE-NeedsTriageHelp Proj-Headless
I haven't been able to reproduce this issue on 60.0.3081.0 anymore, although the screenshots that are created are blank/have no content.
See the attached file for an example.
8.8 KB View Download
It works for me when the "--disable-gpu" flag is passed in along with "--headless".
Are you running the same version (60.0.3081.0)?
And also, on windows?

I'm also passing --disable-gpu.
David, do you remember if we're supposed to end up in in headless mode? I'd expect us to use the aura path instead.
I'll take a look, afaik --screenshot flag essentially uses the same devtools command, so I'm surprised Page.captureScreenshot doesn't work. 
It might be a matter of plumbing it correctly anyway, similar to Mac.
Labels: OS-Mac
I'm not sure this is unique to Windows. I'm seeing this on Mac Canary 60.0.3093.0.

/Applications/ \
    --headless \
    --disable-gpu \

const fs = require('fs');
const chrome = require('chrome-remote-interface');

chrome(async protocol => {
  const {Page} = protocol;

  await Page.enable();

  Page.navigate({url: ''});

  Page.loadEventFired(async timestamp => {
    const {data} = await Page.captureScreenshot();
    fs.writeFileSync('screenshot.png', data, 'base64');

screenshot.png is 1px,1px. Adding --window-size=1280,1696 makes no difference.
Summary: Page.captureScreenshot() fails when running --headless (was: Page.captureScreenshot() fails on Windows when running --headless)
This looks like maybe you're not setting fromSurface=true in the CaptureScreenshot command params? I think headless on windows (and possibly mac?) currently only supports screenshots from the surface.

I think maybe we should be forcing fromSurface=true for headless in general, since anything else doesn't really make sense in headless mode.
You are right Erick, I'll see if it can be forced in headless, otherwise adding fromSurface=true should fix it
Status: Assigned (was: Unconfirmed)
Able to reproduce this on macOS Sierra
 Issue 719900  has been merged into this issue.
fromSurface=True does not seem to resolve the blank screenshots on Mac Sierra for 59.0.3071.47 (Official Build) beta (64-bit).
Hey scott. I can't reproduce your error:

 /Applications/Google\ Chrome\\ Chrome --version
Google Chrome 59.0.3071.47 beta

$ /Applications/Google\ Chrome\\ Chrome --headless --screenshot=headless.png --disable-gpu
[0515/] Written to file headless.png.

Note that the screenshot flag calls Page.CaptureScreenshot(fromSurface=true)

dvallet: I'll prepare a test case. Note that we're attempting to screenshot a canvas element.

The same application works fine when --headless is removed, and --screenshot works fine for us as well.

Here's how we're calling for the screenshot:

        data = {
            "id": self._get_request_id(),
            "method": "Page.captureScreenshot",
            "fromSurface": True,

And what we receive:


Again, removing --headless causes the same call to return a 2.5M image.
Components: Internals>Headless
#19: Do things work if you try capturing something that isn't a canvas?
#21 It does not work. I modified the code to put some text and a number in a div instead of drawing on a canvas. Same issue: non-headless downloads a valid PNG, headless is empty.

Comment 23 by, May 17 2017


Comment 24 by, May 18 2017

Components: Internals>GPU>Testing Tests>Telemetry is the CL changing the default value of the fromSurface argument in the Page.captureScreenshot API. is the CL changing Telemetry to pass "false" for the fromSurface argument all the time. It's important for Chrome's GPU tests that this at least remain an option, even once Telemetry is updated with headless support.

I'd appreciate it if we could land and let Telemetry roll forward before landing . This will avoid losing coverage of important code paths on the tryservers.

Project Member

Comment 25 by, May 18 2017

The following revision refers to this bug:

commit 6f8d636e0a218db1d2b6bee09250566a89eaa02c
Author: <>
Date: Thu May 18 07:51:55 2017

Roll src/third_party/catapult/ d76621c5e..dd9db5d3f (5 commits)

$ git log d76621c5e..dd9db5d3f --date=short --no-merges --format='%ad %ae %s'
2017-05-17 kbr Pass False for fromSurface argument to Page.captureScreenshot.
2017-05-17 rnephew [Telemetry] Rename DisableBenchmark to PermenantlyDisableBenchmark in StoryExpectations
2017-05-17 sullivan Fix typo in api documentation
2017-05-17 kbr Expose browser command line via SystemInfo.
2017-05-17 sullivan Add documenation on the alert list JSON format.

Created with:
  roll-dep src/third_party/catapult
BUG= 714058 ,711065, 718635 

Documentation for the AutoRoller is here:

If the roll is causing failures, see:

Change-Id: I7d0e18ec4ac4032ca270f38f6f406bf1357a33f0
Reviewed-by: <>
Commit-Queue: <>
Cr-Commit-Position: refs/heads/master@{#472727}

Project Member

Comment 26 by, May 24 2017

The following revision refers to this bug:

commit 54bf385aa6becac4aeecd2bf79604bc9421b6306
Author: <>
Date: Wed May 24 03:47:30 2017

Roll src/third_party/catapult/ 51b31788b..f136f4800 (2 commits)

$ git log 51b31788b..f136f4800 --date=short --no-merges --format='%ad %ae %s'
2017-05-23 rnephew [Telemetry] Add android device specific test conditions to StoryExpectations
2017-05-23 kbr Fixed specification of Page.captureScreenshot's fromSurface argument.

Created with:
  roll-dep src/third_party/catapult
BUG=711065, 714058 

Documentation for the AutoRoller is here:

If the roll is causing failures, see:

Change-Id: I5b265c2cf360b33111f678fed0abf43c32790fbf
Reviewed-by: <>
Commit-Queue: <>
Cr-Commit-Position: refs/heads/master@{#474152}

Status: Fixed (was: Assigned)
This should be working now - do I need to download new chromedriver or chrome build for this?

You should be fine if you use chrome canary, otherwise the change will trickle down to dev/beta/stable eventually

Sign in to add a comment