Hi everyone, I need help running a Puppeteer script using the already installed Chrome on my macOS. I tried the following script but couldn’t get it to work:
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'});
})();
Additionally, is there a way to open the Chrome window with a specific size that’s not just the viewport? I attempted using --app-shell-host-window-size=1600x1239
, but it didn’t work. After considering some feedback, I updated my code, and it mostly works except the contents inside are constrained incorrectly. Here is the working part of my code:
const browser = await puppeteer.launch({
headless: false,
args: ['--window-size=2400,1239']
});
Any guidance on resolving these issues would be greatly appreciated.
hey, had similar issue b4… u need to correct the executablePath
: ‘/Applications/Google Chrome.app/Contents/MacOS/Google Chrome’. Also make sure all CSS/js in ur page adapts dynamically to avoid constraint issues. hope this helps 
I encountered a similar problem some time ago, and one trick that worked for me was to ensure the Chromium executable path is correctly stated. Your Puppeteer launch configuration should be adjusted to specify '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
, which directly points to the executable. Also, maintaining the args
parameter with --window-size=2400,1239
provides the needed window dimensions. Ensure your CSS and JavaScript are configured to handle dynamic window resizing to avoid content constraints. This should enhance the display consistency within the window.
Running Puppeteer with an installed version of Chrome on macOS can be a bit tricky if you don’t specify the correct path. You should update your script to:
const puppeteer = require('puppeteer');
(async() => {
const browser = await puppeteer.launch({
headless: false,
executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
args: ['--window-size=2400,1239']
});
const page = await browser.newPage();
await page.goto('http://localhost:8282/publisher/login', {
waitUntil: 'load'
});
await page.screenshot({path: '../screenshots/cms-local.png'});
})();
This adjustment should help in launching Chrome correctly. Regarding the window size, using --window-size
is the correct approach, and it should set the window dimensions rather than just the viewport size.
If the content inside the window seems constrained, check your CSS and JavaScript to ensure they are responsive. They should adapt to different window sizes properly to avoid rendering issues.