title: Detect Chrome running in headless mode from JavaScript
body: <p>With the release of Chrome 59, "headless" mode is <a href="https://www.chromestatus.com/feature/5678767817097216" rel="noreferrer">now available</a> in stable builds for Linux and macOS (and soon also Windows with Chrome 60). This allows us to run a full-featured version of Chrome without any visible UI, a great capability to have for automated testing. <a href="https://developers.google.com/web/updates/2017/04/headless-chrome" rel="noreferrer">Here are examples.</a></p>
  
  <pre class="lang-sh prettyprint-override"><code>chrome --headless --disable-gpu --dump-dom https://stackoverflow.com/
  </code></pre>
  
  <p>In my JavaScript test runner, I like to record as much information as possible about the browser being used, to help isolate issues. For example, I record many of the properties of <code>navigator</code>, including the current browser plugins:</p>
  
  <pre class="lang-js prettyprint-override"><code>JSON.stringify(Array.from(navigator.plugins).map(p =&gt; p.name))
  </code></pre>
  
  <pre class="lang-js prettyprint-override"><code>["Chrome PDF Viewer","Widevine Content Decryption Module","Shockwave Flash","Native Client","Chrome PDF Viewer"]
  </code></pre>
  
  <p>My understanding is that Chrome <em>should</em> behave identically in headless mode, but I have enough experience to be skeptical of a new feature that may significantly change the rendering pipeline.</p>
  
  <p>For now, I am going to run tests in both modes. I would like to the test runner to record whether headless mode is being used. I could pass this information in the test configurations, but I'd rather have a pure JavaScript solution that I can build into the test runner itself. However, I haven't been able to find any browser interface that reveals whether headless mode is active.</p>
  
  <p>Is there any way to detect if Chrome is running in headless mode from JavaScript?</p>