puppeteer: TimeoutError: Timed out after 30000 ms while trying to connect to Chrome!

Hello

I try to implement/deploy puppeteer on Google Cloud but I have some issues. What I don’t understand, it worked well 2 days ago. Since then, I have this error:

TimeoutError: Timed out after 30000 ms while trying to connect to Chrome! The only Chrome revision guaranteed to work is r674921 at Timeout.onTimeout

I ran this command and everything seems fine : DEBUG=* node app.js

Version puppeteer : ^1.19.0 Version Node : v8.11.3

And here the code:

`async function main_screenshot(project_id) { try { const browser = await puppeteer.launch({ headless: true, args: [“–window-size=1440,1000”, “–no-sandbox”, “–disable-setuid-sandbox”, “–disable-gpu”] }); // const browser = await puppeteer.launch({dumpio: true}); const page = await browser.newPage() page.setUserAgent(‘Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36’) page.setViewport({ width: 1440, height: 721 }) console.log(‘entering in screenshot zone’) page.setDefaultNavigationTimeout(30000) await page.goto(‘https://app.slack.com/client/TLW4JE7AA/CLTFQT9GC’) await page.waitFor(3000) await page.type(‘#email’, process.env.SLACK_EMAIL) await page.type(‘#password’, process.env.SLACK_PWD) await page.waitFor(3000) await page.click(‘#signin_btn’) console.log(‘credentials done’) await page.waitFor(3000) console.log(‘so?’) await page.goto(‘https://app.slack.com/client/TLW4JE7AA/CLTFQT9GC’) await page.waitFor(3000) console.log(‘connected to the right environment’) const div = await page.$$(‘.c-message.c-message–light’) var nuwwmber_loop= 0 for (var i = div.length ; i > 0; i–) { var text = await (await div[i - 1].getProperty(‘textContent’)).jsonValue();

  if(text.includes(project_id)) {
    number_loop = i
    break
  }
}
// const text = await (await div.getProperty('textContent')).jsonValue();


 const shotResult = await div[number_loop-1].screenshot();
console.log(shotResult)
cloudinaryOptions = {
  public_id: `${project_id}`
}

const results = await uploadToCloudinary(shotResult, cloudinaryOptions)
console.log(results)
browser.close()
return results

} catch (e) { console.log(e) } }`

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 23
  • Comments: 124

Commits related to this issue

Most upvoted comments

@mathiasbynens I belive this should be reopened, still a lot of people seem to have this error.

If it helps anyone my issue with was due to the usage of Puppeteer in Google Cloud Function and have it running in the background. I changed the function to respond only after Puppeteer is done and it worked just fine.

Hi everyone! I had a similar error: TimeoutError: Timed out after 30000 ms while trying to connect to the browser! Only Chrome at revision r818858 is guaranteed to work.

I fixed it by specifying that particular revision number when launching my puppeteer browser. Note that the revision number on the second line was simply copied and pasted from the error message I received.

  const myFunc = async () => {
    const revisionInfo = await browserFetcher.download('818858');
    
    puppeteer.launch({ executablePath: revisionInfo.executablePath })
      .then(async browser => {
        const page = await browser.newPage();
        ...
      });
  }

Read more about browserFetcher here.

Finally I solved it (at least for my condition).

I’m using Cloud Functions as a Background Function (Triggers when a Firestore Document is created. Though should work for PUB/SUB I imagine).

I needed to make my exported function asynchronous.

Capture

And then you need to await the result.

Capture2

Otherwise, if you look at the Cloud Function logs, you’ll see that your function starts and finishes very quickly (like 200ms). After I made my function asynchronous, it took around 13000ms and stopped giving errors.

Here’s my logs:

BEFORE log01

AFTER log02

For those facing a similar issue, note that this error can come from your process being starved by out of memory. For us, we faced this issue because our kubernetes pod did not have enough memory to answer multiple concurrent requests. Increasing your allocated memory could solve your issue. I suspect too little cpu can also affect the performance as well.

@bruriah1999 your entry function will have a response call. Once invoked the functions technically terminated which means all other tasks are considered background tasks and won’t execute.

Check the Function Execution Timeline in this article https://cloud.google.com/functions/docs/concepts/exec

I use "puppeteer-core": "^1.19.0",

when I use headless: false, it can work. But when I use headless:true, it will be TimeoutError: Navigation Timeout Exceeded: 30000ms exceeded

Yes, but it’s a different kind of error 😃

I got this error only when running on my Apple Silicon (with --platform linux/amd64 ) but it works perfectly on Intel CPU or cloud providers.

I am getting the same error using Cloud functions triggered by pubsub

Error: TimeoutError: Timed out after 30000 ms while trying to connect to the browser! Only Chrome at revision r1036745 is guaranteed to work.

Node 16 puppeteer: “17.1.3”

I had the same problem.

I noticed that if you deploy it using the PUB/SUB trigger, this would happen. If you use HTTP as trigger instead, it runs just fine.

node.js 10 (beta) “puppeteer”: “^2.1.1”, “puppeteer-extra”: “^3.1.9”,

I encounter the same issue on MacOS, after switch to {headless: false} then switch back to {headless: true}, it works. I think the computer need us to allow the chromium first with headless false, after that, it can work in headless mode silently.

This issue is still happening.

I’m using the latest puppeteer version (2.0.0) and receiving this error.

I also sometimes get this error:

C:\node_modules\puppeteer\lib\cjs\puppeteer\node\BrowserRunner.js:252
            reject(new Errors_js_1.TimeoutError(`Timed out after ${timeout} ms while trying to connect to the browser! Only Chrome at revision r${preferredRevision} is guaranteed to work.`));
                   ^
TimeoutError: Timed out after 30000 ms while trying to connect to the browser! Only Chrome at revision r982053 is guaranteed to work.
    at Timeout.onTimeout (C:\node_modules\puppeteer\lib\cjs\puppeteer\node\BrowserRunner.js:252:20)
    at listOnTimeout (node:internal/timers:559:17)
    at processTimers (node:internal/timers:502:7)

It is strange that I set the value to 120,000 for setDefaultTimeout and setDefaultNavigationTimeout, but the error message indicates 30,000!

More code:

async function get_page() {
	if (extra) {
		var pup = puppeteerExtra.use(StealthPlugin());
	} else {
		var pup = puppeteer;
	}
	let options = {
		headless: headless,
		devtools: devtools,
		args: [
			'--no-sandbox',
			'--disable-setuid-sandbox',
			'--proxy-server=' + browser_proxy,
		],
	};
	browser = await pup.launch(options);
	const page = await browser.newPage();
	page.setDefaultTimeout(120*1000);
	page.setDefaultNavigationTimeout(120*1000);
	await page.goto('https://example.com');
	return page;
}

Versions: node v16.14.0 chromium win64-982053 windows 10 headless: true proxy: yes puppeteer-extra-plugin-stealth@2.9.0 puppeteer-page-proxy@1.2.8 puppeteer-proxy@2.1.2 puppeteer@13.7.0

Agreed with @dcts, I am getting the same error with puppeteer 5.2.1

@mathiasbynens #6011 meant to fix **** Exception caught: TimeoutError: Timed out after 30000 ms while trying to connect to the browser! Only Chrome at revision r756035 is guaranteed to work.. ? I updated puppeteer to v4 and still seeing this from time to time.

@tbadlov thank you man, you saved my day, i was struggling here for hours.

If it helps anyone my issue with was due to the usage of Puppeteer in Google Cloud Function and have it running in the background. I changed the function to respond only after Puppeteer is done and it worked just fine.

That’s exactly my problem. What exactly do you mean by changing it to respond only after Puppeteer is done?

It’s magic. I have used my simpliest script last week - it’s work. Today, no updates, but it’s not working with the same issue. It is a normal?

Node: 18.9.0 Pptr: ^18.0.5

We eventually increased the memory limit of our azure function. The timeouts would occur when the page had javascript redirects. So in those cases puppeteer would actually render two pages.

Getting the same issue; node 16 puppeteer 14.3.0

Same problem here ):

@andreabisello just upgraded but still I get the same error. Which is really weird, i have now puppeteer 5.2.1 running, and during install it even logged installing chromium r782078 Bildschirmfoto von 2020-08-01 17-28-18

I removed the launch options:--single-process,it’s work.🤡

So what seemed to fix it for me is to simply make sure I’m spawning only one instance of the browser instead of many. In case of both AWS Lambda/Google Cloud Functions the instance managing the function spins up, the first execution is totally fine, but the next execution (in a short timeframe) will fail, because the chrome instance is already up. A simple solution is to create separate function ala prepareBrowser and make sure to cache the returned browser and check inside the main handler whether it’s there already or not. If it’s there then just re-use it. For example:

let browserPromise: Promise<puppeteer.Browser>;;
const prepareBrowser = async () => {
  // function responsible for launching chrome
}

const handler = () => {
  ...
  if (!browserPromise) {
    browserPromise = prepareBrowser();
  }
  const browser = await browserPromise;
  ...
}

I guess that killing the browser at the end of the function should also solve the problem, but “caching” seems to be more appropriate 🤔 Just make sure you await browser.close(), because if you don’t do await then the browser won’t close properly before the function ends.

Had the same problem. There’s a recent stackoverflow post about running puppeteer on WSL2 and the problem was that my firewall prevented access to my x-server.

I followed the instruction and got it to work!

https://stackoverflow.com/questions/73561240/running-puppeteer-on-wsl2

puppeteer-cluster randomly crashes

image

// Create reference instance
const marked = require('marked')
const Handlebars = require("handlebars");
const fs = require('fs');
const nodeHtmlToImage = require('node-html-to-image');

const githubMarkdownTemplate = fs.readFileSync('./github-markdown-html-template.html', { encoding: 'utf-8' });
const githubMarkdown = marked.parse(`Environment: vdallano%0A%0A### Metadata Failures ###%0A| API Name |Type |Line |Column |Error Message |%0A | ------------- | ------------- | ------------- | ------------- | ------------- |%0A| Order_Record_Page |FlexiPage | | |We couldn't retrieve the design time component information for component c:rhcSignedDocumentUploader. |%0A%0A%0A### Vlocity Errors ###%0A| Errors |%0A | ------------- |%0A| error 1 |%0A| error 2 |%0A| error 3 |`.replaceAll('%0A', '\n'));
const template = Handlebars.compile(githubMarkdownTemplate);
const html = template({
	githubMarkdown
});

//fs.writeFileSync('./github-markdown.html', html, { encoding: 'utf-8' });

nodeHtmlToImage({
	output: './image.png',
	html
})
.then(() => console.log('The image was created successfully!'))
{
  "name": "markdown-2-image",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "handlebars": "^4.7.7",
    "html-to-image": "^1.10.8",
    "marked": "^4.1.1",
    "node-html-to-image": "^3.2.4"
  }
}

@paveltretyakovru did you allocate enough memory?

@paveltretyakovru are you invoking it a lot? I found Firebase Cloud was getting throttled by the website I was connecting to due to the volume of requests. For me it was ~ 5 times a second. I put the function in multiple regions and had the clients randomly pick one as a way to load balance a little to fix it.

@saldous , aloha! Thanks for your attention.

console.log('Launch browser');
const browser = await pup.launch({ headless: false }); 

console.log('Opening page');
const page = await browser.newPage();

console.log('Go to page');
await page.goto('https://google.com');  

My script stoping on “Launch browser”, and I can’t see log with “Opening page”. And after some time I see the issue message.

UPD:

  1. I tried start puppeteer with dart (on wsl space) - not working
  2. I tried start puppeteer with dart in the virtual machine with lubuntu - working
  3. I tried start puppeteer with dart without WSL - working
  4. I tried start puppeteer with nodejs without WSL - working

… so… something wrong with WSL, but I repeat - I used my script many taimes in last month 😦

I am having this issue too, on Firebase Functions. Can’t figure it out. Works fine ~20% of the time and fails all others with timeout.

same node 16 puppeteer 14.1

Same here, working in dev mode, not working in prod mode.

“puppeteer”: “^13.1.1”, node: v12.15.0

Is it in headless: false mode ?

I had the issue on firebase/gcloud, but only once, so I just re-run the function and worked fine, couldn’t replicate it again…

I got this same error (Timed out after 30000 ms while trying to connect to the browser! Only Chrome at revision r818858 is guaranteed to work.) when trying to deploy Puppeteer 5.5.0 to Google Cloud Functions.

I found that it was hanging at await browser.newPage();

This is similar to this issue

Upgrading to Node 12 made no difference. I got it running by downgrading to Puppeteer 2.1.1, and increasing the function memory to 512 MB.

I increased the function memory because I got an out of memory error with 2.1.1. I did check if there was some kind of silent memory issue with 5.5.0, but no, even with 4GB this didn’t run.

Yes google-cloud but I also tried using firebase cloud-functions. Error occurs on both.