Skip to content

Commit d8bca42

Browse files
docs: add Google Cloud Run note to troubleshooting.md doc (#11957)
1 parent c90bc4c commit d8bca42

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

docs/troubleshooting.md

+43-2
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,47 @@ Next, you have to use `'--no-sandbox'` mode and also
483483
passing them as an arguments to your `.launch()` call:
484484
`puppeteer.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox'] });`.
485485

486+
## Running Puppeteer on Google Cloud Run
487+
488+
Google Cloud Run disables the CPU by default, after an HTTP response is written to the client. This means that puppeteer will appear extremely slow (taking 1-5 minutes to launch), if you "run puppeteer in the background" after your response has been written.
489+
490+
So this simple express app will be percievably slow:
491+
492+
```js
493+
import express from 'express';
494+
495+
const app = express();
496+
497+
app.post('/test-puppeteer', (req, res) => {
498+
res.json({
499+
jobId: 123,
500+
acknowledged: true,
501+
});
502+
503+
puppeteer.launch().then(browser => {
504+
// 2 minutes later...
505+
});
506+
});
507+
508+
app.listen(3000);
509+
```
510+
511+
It is slow because CPU is disabled on GCR because puppeteer is launched after the response is sent. What you want to do is this:
512+
513+
```js
514+
app.post('/test-puppeteer', (req, res) => {
515+
puppeteer.launch().then(browser => {
516+
// A second later...
517+
res.json({
518+
jobId: 123,
519+
acknowledged: true,
520+
});
521+
});
522+
});
523+
```
524+
525+
If you want to run the stuff in the background, you need to "enable CPU always" even after responses are sent. That should fix it.
526+
486527
#### Tips
487528

488529
By default, Docker runs a container with a `/dev/shm` shared memory space 64MB.
@@ -535,7 +576,7 @@ module.exports = {
535576
};
536577
```
537578

538-
> [!NOTE]
579+
> [!NOTE]
539580
> Google App Engine caches your `node_modules` between builds.
540581
> Specifying the Puppeteer cache as subdirectory of `node_modules`
541582
> mitigates an issue in which Puppeteer can't find the browser executable
@@ -562,7 +603,7 @@ module.exports = {
562603
};
563604
```
564605

565-
> [!NOTE]
606+
> [!NOTE]
566607
> Google Cloud Functions caches your `node_modules` between builds. Specifying the
567608
> puppeteer cache as subdirectory of `node_modules` mitigates an issue in which the
568609
> puppeteer install process does not run when the cache is hit.

0 commit comments

Comments
 (0)