9951 explained code solutions for 126 technologies


chrome-headlessChrome Launcher usage example


Execute this javascript file using nodejs. This example will launch Chrome in headless mode and close it after 5 seconds:

const chromeLauncher = require('chrome-launcher');

chromeLauncher.launch({
  port: 9222,
  chromeFlags: [ '--headless' ]
}).then(function(chrome) {
  console.log('ok');
  setTimeout(() => chrome.kill(), 1000);
});ctrl + c
require('chrome-launcher')

Chrome-Launcher library to start/stop Chrome browser programmatically

chromeLauncher.launch

launch Chrome with specified params

port: 9222

remote debugging protocol port

chrome.kill()

close browser (or just press Ctrl+C in CLI)