title: Grab a screenshot of Chrome using Chrome Developer Tools?
body: <p>Is it possible to grab a screenshot of an open window using the Chrome Development Tools remote debugger?</p>
  
  <p>For example, I'm connecting to the remote debug port and I have this
  code which pops an empty window:</p>
  
  <pre><code>   private void sendWindowPop(int width, int height) throws
  IOException {
         hsc.send("{\"method\": \"Runtime.evaluate\", \"id\": "
                 + hsc.nextInt()
                 + ", \"params\": {"
                 + "\"expression\":
  \"window.open('about:blank','name','toolbar=0,scrollbars=0,"
                 + "location=0,status=0,menubar=0,resizable=0,width="
                 + width
                 + ",height="
                 + height
                 + "');\""
                 + "}}");
  </code></pre>
  
  <p>(hsc is my connection to the debugger at <a href="http://localhost:9222" rel="noreferrer">http://localhost:9222</a>)</p>
  
  <p>Then, I load up my target URL with this:</p>
  
  <pre><code>    private void loadPage(String uriString) throws IOException {
         hsc.send("{\"method\": \"Page.open\", \"id\": " +
         hsc.nextInt() + ", \"params\": {\"url\": \"" + uriString + "\"}}");
         hsc.waitFor(ChromeNotifications.PAGE_LOADEVENTFIRED, DEFAULT_TIMEOUT_MILLIS);
     }
  </code></pre>
  
  <p>The code above works fine, and first pops a window and then loads the
  URL.  Ideally, the next thing I would like to do is grab a screenshot
  of the loaded web page.  Right now, these browser windows pop into an
  Xvfb virtual desktop, and I can use ImageMagick's import tool to grab
  a screenshot of the target window, but <em>only if it's in the
  foreground</em>.</p>
  
  <p>This is a problem, since this application is designed to run in
  parallel with multiple windows popping into the virtual desktop.  Any
  window overlapping my target window will just give me a black
  screenshot, since Xfvb only renders what's visible.</p>
  
  <p>I also looked into the API reference, chrome.tabs.captureVisibleTab.  No luck there, it doesn't capture what's not visible.</p>
  
  <p>Is there a way, using the remote debugger, to grab a screenshot of an
  open window?</p>
  
  <p>(for reference purposes, my ImageMagick command for import is this)</p>
  
  <pre><code>    DISPLAY=:0.0 import -window "Google - Chromium" screenshot.png
  </code></pre>
  
  <p>Where I open the URL <a href="http://www.google.com" rel="noreferrer">http://www.google.com</a> in my chromium browser using loadPage() above.  It works great as long as the "Google - Chromium" window that pops is unobstructed and has focus.  Drop another window over part of it, and I get a big black area that was not rendered.</p>
  
  <p>Thanks!</p>