Here is the command for creating a Chrome profile on the command line.
google-chrome --remote-debugging-port=9222 --user-data-dir="/home/nishant/Nishant system/nishant/nishant_puppeteer" --profile-directory="puppeteer_chrome"
When I execute this command on cmd I am able to get output like this:
DevTools listening on ws://[::1]:9222/devtools/
But when I execute this command using NodeJS, I am not able to get the output as I need to store that output in variable without ending the browser.
Code I tried:
const puppeteer = require('puppeteer');
const util = require('util');
// const { spawn } = require('child_process');
// const child_process = require('child_process');
const { spawn } = require('child_process');
(async () => {
const child = spawn('',[
'/bin/sh',
'-c',
'google-chrome --remote-debugging-port=9222 --user-data-dir="/home/nishant/Nishant system/nishant/nishant_puppeteer" --profile-directory="puppeteer_chrome"'
]);
child.stdout.on('data', (chunk) => {
// data from standard output is here as buffers
console.log(chunk)
});
const browser = await puppeteer.connect(
{ browserWSEndpoint: 'ws://127.0.0.1:9222/devtools/browser/852aa513-077d-4b93-aedd-34ae789be51c'}
);
const pages = await browser.pages();
const page = pages[0];
await page.goto('https://www.example.com');
// const page = await browser.newPage();
await page.goto('https://partners.myntrainfo.com/');
Rest of your code here
})();