You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
+
486
527
#### Tips
487
528
488
529
By default, Docker runs a container with a `/dev/shm` shared memory space 64MB.
@@ -535,7 +576,7 @@ module.exports = {
535
576
};
536
577
```
537
578
538
-
> [!NOTE]
579
+
> [!NOTE]
539
580
> Google App Engine caches your `node_modules` between builds.
540
581
> Specifying the Puppeteer cache as subdirectory of `node_modules`
541
582
> mitigates an issue in which Puppeteer can't find the browser executable
@@ -562,7 +603,7 @@ module.exports = {
562
603
};
563
604
```
564
605
565
-
> [!NOTE]
606
+
> [!NOTE]
566
607
> Google Cloud Functions caches your `node_modules` between builds. Specifying the
567
608
> puppeteer cache as subdirectory of `node_modules` mitigates an issue in which the
568
609
> puppeteer install process does not run when the cache is hit.
0 commit comments