Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

run puppeteer on already installed chrome on macos

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"]


    });

enter image description here

like image 645
Mohamed Hussain Avatar asked Nov 05 '17 14:11

Mohamed Hussain


People also ask

How do you connect already existing Chrome browser with puppeteer?

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.

Does puppeteer require Chrome installed?

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.

Where is puppeteer Chromium?

The Chromium browser is downloaded in the /node_modules/puppeteer folder when you install the Puppeteer package.


2 Answers

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

enter image description here

like image 102
xialvjun Avatar answered Oct 19 '22 02:10

xialvjun


For me it worked when I set executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'

like image 31
vitmalina Avatar answered Oct 19 '22 03:10

vitmalina