title: Headless chrome launcher --window-size causing error
body: <p>I need to be able to take screenshot given a certain window size. I read this blog post on <a href="https://web.archive.org/web/20200220022511/http://phptest.club/t/how-to-run-headless-chrome-in-codeception/1544" rel="nofollow noreferrer">How to run Headless Chrome in Codeception</a> and this page on <a href="https://developers.google.com/web/updates/2017/04/headless-chrome" rel="nofollow noreferrer">Getting Started with Headless Chrome</a> but could not figure out how to resize the window at init.</p>
  <p>I have tried to pass <code>--window-size</code> in all options below and none work:</p>
  <pre class="lang-sh prettyprint-override"><code>--window-size=1280,1696
  --window-size=1280x1696
  --window-size 1280,1696
  --window-size 1280x1696
  </code></pre>
  <p><em>Worst of all</em>, now my screenshot is blank after doing this for awhile. Is there some kind of memory retained in the headless browser causing this? I have not tried to reboot my Mac yet which is probably next.</p>
  <p><strong>So what is a way to take full page screenshot given window size?</strong> In phantom.js, this is a very trivial thing.</p>
  <p>My code is below</p>
  <pre class="lang-js prettyprint-override"><code>const chromeLauncher = require('chrome-launcher');
  const CDP = require('chrome-remote-interface');
  const file = require('fs');
  
  (async function() {
    async function launchChrome() {
      return await chromeLauncher.launch({
        chromeFlags: [
          '--window-size=1280,1696',
          '--disable-gpu',
          '--headless'
        ]
      });
    }
    const chrome = await launchChrome();
    const protocol = await CDP({
      port: chrome.port
    });
  
    const {
      DOM,
      Network,
      Page,
      Emulation,
      Runtime
    } = protocol;
    await Promise.all([Network.enable(), Page.enable(), Runtime.enable(), DOM.enable()]);
  
    Page.navigate({
      url: 'https://www.yahoo.com/'
    });
  
    Page.loadEventFired(async() =&gt; {
  
      console.log('Start Page.loadEventFired');
      const script1 = &quot;document.querySelector('p').textContent&quot;
      const result = await Runtime.evaluate({
        expression: script1
      });
      console.log(result.result.value);
  
      const ss = await Page.captureScreenshot({format: 'png', fromSurface: false});
      file.writeFile('output.png', ss.data, 'base64', function(err) {
        if (err) {
          console.log(err);
        }
      });
  
      protocol.close();
      chrome.kill(); 
    });
  
  })();
  </code></pre>
  <p>If I do this in command line, it works fine:</p>
  <pre class="lang-sh prettyprint-override"><code>alias chrome-canary=&quot;/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary&quot;
  
  chrome-canary --headless --disable-gpu --screenshot --window-size=300,1696 https://www.yahoo.com/
  </code></pre>
  <h3>UPDATE</h3>
  <p>I realized headless Chrome Canary is very unstable on the Mac at least. If I close down the Terminal and start it fresh, sometime it works. But then after running exactly the same script, it just hung up forever (I left overnight). I just updated everything (Chrome Canary, chrome-launcher, chrome-remote-interface) today and continue to debug. Maybe it's not its prime time yet.</p>