Project: chromium Issues People Development process History Sign in
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
Status: Fixed
Owner:
Closed: May 30
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Windows, Mac
Pri: 2
Type: Bug



Sign in to add a comment
Page.captureScreenshot() fails when running --headless
Reported by rutterp...@gmail.com, Apr 21 Back to list
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 http://www.abhishekshukla.com/chrome/capture-screenshot-in-chrome-without-any-tool-plugin-extension/ 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/101318.467:ERROR:snapshot_win.cc(56)] Failed to print window: Invalid window handle. (0x578)
Chrome stderr [0421/101318.467:ERROR:snapshot_win.cc(144)] 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
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.
example_windows_screenshot.png
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.
Cc: dvallet@chromium.org
David, do you remember if we're supposed to end up in snapshot_win.cc 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.
Owner: dvallet@chromium.org
Labels: OS-Mac
I'm not sure this is unique to Windows. I'm seeing this on Mac Canary 60.0.3093.0.

/Applications/Chromium.app/Contents/MacOS/Chromium \
    --headless \
    --disable-gpu \
    --remote-debugging-port=9222


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

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

  await Page.enable();

  Page.navigate({url: 'https://www.chromestatus.com/features'});

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

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
Able to reproduce this on macOS Sierra
Cc: jzfeng@chromium.org skyos...@chromium.org irisu@chromium.org
 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\ 3.app/Contents/MacOS/Google\ Chrome --version
Google Chrome 59.0.3071.47 beta

$ /Applications/Google\ Chrome\ 3.app/Contents/MacOS/Google\ Chrome --headless --screenshot=headless.png --disable-gpu http://www.example.com
[0515/104708.382429:INFO:headless_shell.cc(436)] 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:

{"id":5,"result":{"data":"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAAtJREFUCB1jYAACAAAFAAGNu5vzAAAAAElFTkSuQmCC"}}

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.
Cc: kbr@chromium.org
Cc: nedngu...@google.com rmis...@chromium.org
Components: Internals>GPU>Testing Tests>Telemetry
https://codereview.chromium.org/2871113002/ is the CL changing the default value of the fromSurface argument in the Page.captureScreenshot API.

https://codereview.chromium.org/2887023002/ 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 https://codereview.chromium.org/2887023002/ and let Telemetry roll forward before landing https://codereview.chromium.org/2871113002/ . This will avoid losing coverage of important code paths on the tryservers.

Project Member Comment 25 by bugdroid1@chromium.org, May 18
The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/6f8d636e0a218db1d2b6bee09250566a89eaa02c

commit 6f8d636e0a218db1d2b6bee09250566a89eaa02c
Author: catapult-deps-roller@chromium.org <catapult-deps-roller@chromium.org>
Date: Thu May 18 07:51:55 2017

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

https://chromium.googlesource.com/external/github.com/catapult-project/catapult.git/+log/d76621c5ec84..dd9db5d3f658

$ 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:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md

If the roll is causing failures, see:
http://www.chromium.org/developers/tree-sheriffs/sheriff-details-chromium#TOC-Failures-due-to-DEPS-rolls


CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.android:android_optional_gpu_tests_rel
TBR=sullivan@chromium.org

Change-Id: I7d0e18ec4ac4032ca270f38f6f406bf1357a33f0
Reviewed-on: https://chromium-review.googlesource.com/508260
Reviewed-by: <catapult-deps-roller@chromium.org>
Commit-Queue: <catapult-deps-roller@chromium.org>
Cr-Commit-Position: refs/heads/master@{#472727}
[modify] https://crrev.com/6f8d636e0a218db1d2b6bee09250566a89eaa02c/DEPS

Project Member Comment 26 by bugdroid1@chromium.org, May 24
The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/54bf385aa6becac4aeecd2bf79604bc9421b6306

commit 54bf385aa6becac4aeecd2bf79604bc9421b6306
Author: catapult-deps-roller@chromium.org <catapult-deps-roller@chromium.org>
Date: Wed May 24 03:47:30 2017

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

https://chromium.googlesource.com/external/github.com/catapult-project/catapult.git/+log/51b31788b65c..f136f480014c

$ 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:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md

If the roll is causing failures, see:
http://www.chromium.org/developers/tree-sheriffs/sheriff-details-chromium#TOC-Failures-due-to-DEPS-rolls


CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.android:android_optional_gpu_tests_rel
TBR=sullivan@chromium.org

Change-Id: I5b265c2cf360b33111f678fed0abf43c32790fbf
Reviewed-on: https://chromium-review.googlesource.com/513473
Reviewed-by: <catapult-deps-roller@chromium.org>
Commit-Queue: <catapult-deps-roller@chromium.org>
Cr-Commit-Position: refs/heads/master@{#474152}
[modify] https://crrev.com/54bf385aa6becac4aeecd2bf79604bc9421b6306/DEPS

Status: Fixed
This should be working now
@dvallet@chrominum.org - 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