1.How can I run the Puppeteer script on the already installed chrome in mac machine. I tried with the following script, not able to run.
2.Is there any way to open the chrome window with particular window size here I am not talking about viewport, I tried with args "--app-shell-host-window-size=1600x1239" -- not working.
Could anyone help me on the above two issues. Thanks in advance for any help
const puppeteer = require('puppeteer');
(async() => {
const browser = await puppeteer.launch({
headless: false,
executablePath: '/Applications/Google Chrome.app/',
args: ["--app-shell-host-window-size=1600x1239"]
});
const page = await browser.newPage();
await page.goto('http://localhost:8282/publisher/login' ,{
waitUntil: 'load'
});
await page.screenshot({path: '../screenshots/cms-local.png'});
//await browser.close();
})();
After Following the Eric Comment and jegadesh answer below, I changed the code like below and Now it is working except one small issue: window is opening in correct size but content in that window are constrained to some other size, see the screenshot below
Working Code:
const browser = await puppeteer.launch({
headless: false,
// executablePath: '/Applications/Google Chrome.app/',
args: ["--window-size=2400,1239"]
});
You can connect to an existing using the connect function: const browserURL = 'http://127.0.0.1:21222'; const browser = await puppeteer. connect({browserURL}); But, if you want to use those 2 lines you need to launch Chrome with the "--remote-debugging-port=21222 argument.
Puppeteer is a Node. js library developed by Google that lets you control headless Chrome through the DevTools Protocol. It is a tool for automating testing in your application using headless Chrome or Chromebit devices, without requiring any browser extensions like Selenium Webdriver or PhantomJS.
The Chromium browser is downloaded in the /node_modules/puppeteer folder when you install the Puppeteer package.
You can set executablePath: '/Applications/Google Chrome.app/'
...
You can browse chrome://version/
in chrome, and find executableFilePath
(maybe it's not this name, my chrome is not english version), use this.
See Screenshot Below
For me it worked when I set executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With