1

I am trying to set up chrome-launcher to output all console messages to terminal. My code looks like this

const chromeLauncher = require('chrome-launcher');
const CDP = require('chrome-remote-interface');

(async function() {
  async function launchChrome() {
    return await chromeLauncher.launch({
      chromeFlags: [
        '--window-size=1200,800',
        '--user-data-dir=/tmp/chrome-testing',
        '--auto-open-devtools-for-tabs'
      ]
    });
  }
  const chrome = await launchChrome();
  const protocol = await CDP({
    port: chrome.port
  });

  const {
    DOM,
    Network,
    Page,
    Runtime,
    Console
  } = protocol;

  await Promise.all([Network.enable(), Page.enable(), DOM.enable(), Runtime.enable(), Console.enable()]).catch(console.log);

  // REMARKS: messageAdded is fired every time a new console message is added
  Console.messageAdded((result) => {
    console.log(result);
  });

})();

I copied some of this from the question here: How to get console.log output in Terminal via Headless Chrome Runtime.evaluate

When I try to navigate to a page, none of the console messages show up in the terminal, and the chrome-launcher exits with the following error:

(node:14531) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:64656
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1083:14)
(node:14531) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:14531) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. 
Jeremy Gottfried
  • 1,061
  • 13
  • 28

0 Answers0