<p dir="auto">Please, implement the headless option which is available from chrome version 57.</p>
<p dir="auto">Reason:<br>
Easier usage for testing and scraping (without the xfb hack)</p>
<ul dir="auto">
<li>Electron version: 1.6.x</li>
<li>Operating system: macOS</li>
</ul>
<h3 dir="auto">Expected behavior</h3>
<p dir="auto">Several things:</p>
<ul dir="auto">
<li>The promise which is returned by executeJavascript should be rejected</li>
<li>The error and stack trace should be more meaningful (how? = what's possible?)</li>
<li>Furthermore if you listen of global errors with the debugger trough the <code class="notranslate">Runtime.exceptionThrown</code> event - there is currently no way to locate where exactly the error happened. By the way the below error output is captured by this event. There must be a way to identify the script somehow or even better return the source to create a code frame. (compile a named code or so? don't know exactly how it works...)</li>
</ul>
<h3 dir="auto">Actual behavior</h3>
<p dir="auto">When call webContents.executeJavascript and the passed javascript has a syntax error.<br>
There are several problems which make it difficult to debug:</p>
<ul dir="auto">
<li>The stack trace is useless (see screenshot)</li>
<li>The returned promise from <code class="notranslate">executeJavascript</code> hangs in the <code class="notranslate">pending</code> state</li>
<li>No identification to which injected JS it belongs to (can be skipped if the previous point is solved smart)</li>
</ul>
<h3 dir="auto">How to reproduce</h3>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="webContents.executeJavascript('just some syntax error')"><pre class="notranslate"><span class="pl-s1">webContents</span><span class="pl-kos">.</span><span class="pl-en">executeJavascript</span><span class="pl-kos">(</span><span class="pl-s">'just some syntax error'</span><span class="pl-kos">)</span></pre></div>
<h2 dir="auto">Appendix</h2>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/1138623/24971037/c5449510-1fb6-11e7-8b89-086ae5d40db1.png"><img width="997" alt="bildschirmfoto 2017-04-12 um 19 26 47" src="https://cloud.githubusercontent.com/assets/1138623/24971037/c5449510-1fb6-11e7-8b89-086ae5d40db1.png" style="max-width: 100%;"></a></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{ columnNumber: 4,
  exception: 
   { className: 'SyntaxError',
     description: 'SyntaxError: Unexpected identifier\n    at EventEmitter.electron.ipcRenderer.on (/Users/xxx/yyy/js_package_nightmare-service/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar/renderer/init.js:52:28)\n    at emitMany (events.js:127:13)\n    at EventEmitter.emit (events.js:201:7)',
     objectId: '{&quot;injectedScriptId&quot;:1,&quot;id&quot;:1}',
     preview: 
      { description: 'SyntaxError: Unexpected identifier\n    at EventEmitter.electron.ipcRenderer.on (/Users/xxx/yyy/js_package_nightmare-service/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar/renderer/init.js:52:28)\n    at emitMany (events.js:127:13)\n    at EventEmitter.emit (events.js:201:7)',
        overflow: false,
        properties: 
         [ { name: 'stack',
             type: 'string',
             value: 'SyntaxError: Unexpected identifier\n    at EventEmi…27:13)\n    at EventEmitter.emit (events.js:201:7)' },
           { name: 'message',
             type: 'string',
             value: 'Unexpected identifier' },
           [length]: 2 ],
        subtype: 'error',
        type: 'object' },
     subtype: 'error',
     type: 'object' },
  exceptionId: 1,
  executionContextId: 1,
  lineNumber: 0,
  scriptId: '112',
  stackTrace: 
   { callFrames: 
      [ { columnNumber: 27,
          functionName: 'electron.ipcRenderer.on',
          lineNumber: 51,
          scriptId: '65',
          url: '/Users/xxx/yyy/js_package_nightmare-service/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar/renderer/init.js' },
        { columnNumber: 12,
          functionName: 'emitMany',
          lineNumber: 126,
          scriptId: '30',
          url: 'events.js' },
        { columnNumber: 6,
          functionName: 'emit',
          lineNumber: 200,
          scriptId: '30',
          url: 'events.js' },
        [length]: 3 ] },
  text: 'Uncaught' }"><pre class="notranslate"><span class="pl-kos">{</span> <span class="pl-c1">columnNumber</span>: <span class="pl-c1">4</span><span class="pl-kos">,</span>
  <span class="pl-c1">exception</span>: 
   <span class="pl-kos">{</span> <span class="pl-c1">className</span>: <span class="pl-s">'SyntaxError'</span><span class="pl-kos">,</span>
     <span class="pl-c1">description</span>: <span class="pl-s">'SyntaxError: Unexpected identifier\n    at EventEmitter.electron.ipcRenderer.on (/Users/xxx/yyy/js_package_nightmare-service/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar/renderer/init.js:52:28)\n    at emitMany (events.js:127:13)\n    at EventEmitter.emit (events.js:201:7)'</span><span class="pl-kos">,</span>
     <span class="pl-c1">objectId</span>: <span class="pl-s">'{"injectedScriptId":1,"id":1}'</span><span class="pl-kos">,</span>
     <span class="pl-c1">preview</span>: 
      <span class="pl-kos">{</span> <span class="pl-c1">description</span>: <span class="pl-s">'SyntaxError: Unexpected identifier\n    at EventEmitter.electron.ipcRenderer.on (/Users/xxx/yyy/js_package_nightmare-service/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar/renderer/init.js:52:28)\n    at emitMany (events.js:127:13)\n    at EventEmitter.emit (events.js:201:7)'</span><span class="pl-kos">,</span>
        <span class="pl-c1">overflow</span>: <span class="pl-c1">false</span><span class="pl-kos">,</span>
        <span class="pl-c1">properties</span>: 
         <span class="pl-kos">[</span> <span class="pl-kos">{</span> <span class="pl-c1">name</span>: <span class="pl-s">'stack'</span><span class="pl-kos">,</span>
             <span class="pl-c1">type</span>: <span class="pl-s">'string'</span><span class="pl-kos">,</span>
             <span class="pl-c1">value</span>: <span class="pl-s">'SyntaxError: Unexpected identifier\n    at EventEmi…27:13)\n    at EventEmitter.emit (events.js:201:7)'</span> <span class="pl-kos">}</span><span class="pl-kos">,</span>
           <span class="pl-kos">{</span> <span class="pl-c1">name</span>: <span class="pl-s">'message'</span><span class="pl-kos">,</span>
             <span class="pl-c1">type</span>: <span class="pl-s">'string'</span><span class="pl-kos">,</span>
             <span class="pl-c1">value</span>: <span class="pl-s">'Unexpected identifier'</span> <span class="pl-kos">}</span><span class="pl-kos">,</span>
           <span class="pl-kos">[</span><span class="pl-s1">length</span><span class="pl-kos">]</span>: <span class="pl-c1">2</span> <span class="pl-kos">]</span><span class="pl-kos">,</span>
        <span class="pl-c1">subtype</span>: <span class="pl-s">'error'</span><span class="pl-kos">,</span>
        <span class="pl-c1">type</span>: <span class="pl-s">'object'</span> <span class="pl-kos">}</span><span class="pl-kos">,</span>
     <span class="pl-c1">subtype</span>: <span class="pl-s">'error'</span><span class="pl-kos">,</span>
     <span class="pl-c1">type</span>: <span class="pl-s">'object'</span> <span class="pl-kos">}</span><span class="pl-kos">,</span>
  <span class="pl-c1">exceptionId</span>: <span class="pl-c1">1</span><span class="pl-kos">,</span>
  <span class="pl-c1">executionContextId</span>: <span class="pl-c1">1</span><span class="pl-kos">,</span>
  <span class="pl-c1">lineNumber</span>: <span class="pl-c1">0</span><span class="pl-kos">,</span>
  <span class="pl-c1">scriptId</span>: <span class="pl-s">'112'</span><span class="pl-kos">,</span>
  <span class="pl-c1">stackTrace</span>: 
   <span class="pl-kos">{</span> <span class="pl-c1">callFrames</span>: 
      <span class="pl-kos">[</span> <span class="pl-kos">{</span> <span class="pl-c1">columnNumber</span>: <span class="pl-c1">27</span><span class="pl-kos">,</span>
          <span class="pl-c1">functionName</span>: <span class="pl-s">'electron.ipcRenderer.on'</span><span class="pl-kos">,</span>
          <span class="pl-c1">lineNumber</span>: <span class="pl-c1">51</span><span class="pl-kos">,</span>
          <span class="pl-c1">scriptId</span>: <span class="pl-s">'65'</span><span class="pl-kos">,</span>
          <span class="pl-c1">url</span>: <span class="pl-s">'/Users/xxx/yyy/js_package_nightmare-service/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar/renderer/init.js'</span> <span class="pl-kos">}</span><span class="pl-kos">,</span>
        <span class="pl-kos">{</span> <span class="pl-c1">columnNumber</span>: <span class="pl-c1">12</span><span class="pl-kos">,</span>
          <span class="pl-c1">functionName</span>: <span class="pl-s">'emitMany'</span><span class="pl-kos">,</span>
          <span class="pl-c1">lineNumber</span>: <span class="pl-c1">126</span><span class="pl-kos">,</span>
          <span class="pl-c1">scriptId</span>: <span class="pl-s">'30'</span><span class="pl-kos">,</span>
          <span class="pl-c1">url</span>: <span class="pl-s">'events.js'</span> <span class="pl-kos">}</span><span class="pl-kos">,</span>
        <span class="pl-kos">{</span> <span class="pl-c1">columnNumber</span>: <span class="pl-c1">6</span><span class="pl-kos">,</span>
          <span class="pl-c1">functionName</span>: <span class="pl-s">'emit'</span><span class="pl-kos">,</span>
          <span class="pl-c1">lineNumber</span>: <span class="pl-c1">200</span><span class="pl-kos">,</span>
          <span class="pl-c1">scriptId</span>: <span class="pl-s">'30'</span><span class="pl-kos">,</span>
          <span class="pl-c1">url</span>: <span class="pl-s">'events.js'</span> <span class="pl-kos">}</span><span class="pl-kos">,</span>
        <span class="pl-kos">[</span><span class="pl-s1">length</span><span class="pl-kos">]</span>: <span class="pl-c1">3</span> <span class="pl-kos">]</span> <span class="pl-kos">}</span><span class="pl-kos">,</span>
  <span class="pl-c1">text</span>: <span class="pl-s">'Uncaught'</span> <span class="pl-kos">}</span></pre></div>