9951 explained code solutions for 126 technologies

chrome-headlessHow to send commands to Chrome debugging port

In order to keep running, we should enable debugging port, so Chrome knows we want it to stay:

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

CDP(async (client) => {
  const {Page} = client;
  await Page.enable();
  await Page.navigate({url: 'https://onelinerhub.com'});
  await Page.loadEventFired();
  console.log('page is loaded, ok');
  await client.close();
});ctrl + c

Chrome-Remote-Interface library to operate

CDP(async (client)

init remote debugging interface connection when browser is ready


go to specified URL

await Page.loadEventFired()

wait while page is loaded


print some text to console (add code to manipulate Chrome here)


close remote debugging interface connection