question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Puppeteer with headless:true is extremely slow

See original GitHub issue

Though this issues has been raised in https://github.com/GoogleChrome/puppeteer/issues/1550, but it was closed and the problem was not addressed.

My environment:

  • Puppeteer Version: “puppeteer”: “^0.13.0”
  • Windows Server 2008 R2 Enterprise with Service Pack 1 & command prompt

With the following minimal test script:

const puppeteer = require('puppeteer');

const headless = process.argv[2] === "headless";

(async () => {
    const timeout = 30000
    const browser = await puppeteer.launch({
        headless: headless,
        timeout,
    });
    const page = await browser.newPage();
	const label = "Go to Bing " + (headless?"without": "with") + " head."
	console.time(label)
    await page.goto("https://www.bing.com/", { timeout })
	const title = await page.title()
	console.log("Title: " + title)
	console.timeEnd(label);
    await browser.close();
})();

image

headless.log head.log

To aid debugging, I turned on debugging and collected two logs: headless.log & head.log respectively.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:10
  • Comments:32 (5 by maintainers)

github_iconTop GitHub Comments

59reactions
ChiggerChugcommented, Jun 15, 2018

Hey guys, so I’ve found a workaround for this. I found the answer in another thread unrelated to puppeteer but also has the problem with chromium being extremely slow in headless mode. I noticed that when I tried to debug chromium that network requests were the slow bit in terms of headless mode so I searched for that.

const browser = await puppeteer.launch({args: ["--proxy-server='direct://'", '--proxy-bypass-list=*']})

When launching the browser add these 2 arguments to the list and it seems (for me anyway) to resolve all issues with speed.

Link to thread if you’re interested: https://github.com/Codeception/CodeceptJS/issues/561 and props to oligee80 (who found the answer) for saving me about a week of work rolling back a bunch of product releases! 🎉

18reactions
MaDethocommented, Sep 29, 2018

Try setting a valid UserAgent. This worked for me.

await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36')
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to speed up puppeteer? - Stack Overflow
It can really depends on the site you are visiting, but you are able to speed up the process of recognition of your...
Read more >
Improving Puppeteer Performance - browserless docs
One of the things that stands out when using a headless browser (versus cURL or other simpler tools) is that it can be...
Read more >
Now that i have puppeteer working, it is extremely slow
So i implemented a couple lines to see how long it takes to set cookies, it takes anywhere from 8-16 seconds JUST to...
Read more >
Why is Playwright and Puppeteer so slow? Am I using it wrong?
Non-headless actually seems to be faster for whatever reason. ... For scrapping they are too slow, because they are fully rendering content ......
Read more >
8 Tips for Faster Puppeteer Screenshots - Bannerbear
When optimizing Puppeteer, remember that there are only so many ways to speed ... browser = await puppeteer.launch({ headless: true, args: minimal_args }) ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found