How do I use Headless Chrome in Chrome 60 on Windows 10?

后端 未结 6 1067
一生所求
一生所求 2020-12-29 00:56

I\'ve been looking at the following article about Headless Chrome:
https://developers.google.com/web/updates/2017/04/headless-chrome

I just upgraded Chrome on Wi

6条回答
  •  感情败类
    2020-12-29 01:49

    Current versions (68-70) seem to require --no-sandbox in order to run, without it they do absolutely nothing and hang in the background.

    The full commands I use are:

    chrome --headless --user-data-dir=tmp --no-sandbox --enable-logging --dump-dom https://www.google.com/ > file.html
    chrome --headless --user-data-dir=tmp --no-sandbox --print-to-pdf=whatever.pdf https://www.google.com/
    

    Using --no-sandbox is a pretty bad idea and you should use this only for websites you trust, but sadly it's the only way of making it work at all.

    --user-data-dir=... uses the specified directory instead of the default one, which is likely already in use by your regular browser.

    However, if you're trying to make a PDF from HTML, then this is fairly useless, since you can't remove header and footer (containing text like file:///...) and the only viable solution is to use Puppeteer.

提交回复
热议问题