Chrome Launcher завершает работу с UnhandledPromiseRejectionWarning - PullRequest
0 голосов
/ 21 марта 2019

Я пытаюсь настроить chrome-launcher для вывода всех консольных сообщений на терминал. Мой код выглядит так

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);
  });

})();

Я скопировал кое-что из этого вопроса: Как получить файл console.log в Терминале через Headless Chrome Runtime.evaluate

Когда я пытаюсь перейти на страницу, ни одно из консольных сообщений не появляется в терминале, и chrome-launcher завершается со следующей ошибкой:

(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. 
...