30

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

Mosh Feu
  • 28,354
  • 16
  • 88
  • 135
Mohamed Hussain
  • 7,433
  • 14
  • 55
  • 85
  • 1
    Check out --window-size and the path used in https://developers.google.com/web/updates/2017/04/headless-chrome – ebidel Nov 06 '17 at 14:52
  • 1
    Thanks Eric...I am able to run on the already installed chrome by giving the path you mentioned in the article for MAC chrome developers.google.com/web/updates/2017/04/headless-chrome ...Window size is also is working, but after running the script, It opens the window in correct size , but content in the window is looking constrained to some other width, see the screenshot, then I go to the opened page , and I open the devtools using mouseclick, the content size is readjusted to the entire window size. I corrected this issue to using await page.setViewport({width: 2300, height:1239}); – Mohamed Hussain Nov 07 '17 at 11:34
  • Is there anyway to sync the viewport with existing window size – Mohamed Hussain Nov 07 '17 at 11:36
  • @ebidel: Is there a way to open the chrome with certain profile, from the doc I assume that there is no way, Is any hack or any future plan to support this? because I planned to automate the login for my local CMS and then I go and work on the page with my Profile On, so that I could run snippets from devtools – Mohamed Hussain Nov 07 '17 at 11:39
  • @ebidel on https://try-puppeteer.appspot.com/ I am getting one or other error always when running the example given, even not able to run the code which is running successfully on my local machine, sorry for raising this silly issues – Mohamed Hussain Nov 07 '17 at 12:14

3 Answers3

95

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

Faiz Mohammed
  • 344
  • 3
  • 11
xialvjun
  • 1,090
  • 7
  • 10
24

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

vitmalina
  • 1,829
  • 1
  • 14
  • 7
1

Regarding your first question, Puppeteer docs indicate that it could work with an installed version of Chromium or Chrome.

To use an installed version:

Regarding your second question, use --window-size. For example: "--window-size=800,600"

Please be aware that if you have opened a browser window with an explicitly set window-size, then that size will be used for all future windows (ignoring any size you specify for the future windows). For a new window-size to be effective, you must close all previously opened windows.

gjegadesh
  • 144
  • 10
  • 1
    The docs currently state that `puppeteer.launch([options])` accepts `executablePath`: Path to a Chromium or Chrome executable to run instead of the bundled Chromium. link: https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerlaunchoptions – dean grande Oct 25 '19 at 02:45
  • 3
    This answer is not accurate. You can use chrome, I just tested it. – codepleb Feb 25 '20 at 07:10