Sparticuz / chromium

Chromium (x86-64) for Serverless Platforms
MIT License
923 stars 62 forks source link

[REQUEST] Investigate Chromium launch flags #3

Open Sparticuz opened 1 year ago

Sparticuz commented 1 year ago

https://github.com/GoogleChrome/chrome-launcher/blob/main/docs/chrome-flags-for-tools.md

hansottowirtz commented 1 year ago

I've upgraded from chrome-aws-lambda@9.1.0, but some of the heaviest pages we have to render crashed Chrome, unlike chrome-aws-lambda. The errors are usually: ProtocolError: Protocol error (Page.printToPDF): Printing failed.

Reverting to the flags of chrome-aws-lambda seemed to solve the problem. This is the diff, I will try to try every flag to figure out which one fixes it.

diff --git a/src/legacy-args.ts b/src/new-args.ts
index 87a81f4..7a1f8c5 100644
--- a/src/legacy-args.ts
+++ b/src/new-args.ts
@@ -1,40 +1,28 @@
-export const legacyArgs = [
+export const newArgs = [
   '--autoplay-policy=user-gesture-required',
-  '--disable-background-networking',
   '--disable-background-timer-throttling',
-  '--disable-backgrounding-occluded-windows',
-  '--disable-breakpad',
-  '--disable-client-side-phishing-detection',
   '--disable-component-update',
-  '--disable-default-apps',
   '--disable-dev-shm-usage',
   '--disable-domain-reliability',
-  '--disable-extensions',
   '--disable-features=AudioServiceOutOfProcess,IsolateOrigins,site-per-process',
-  '--disable-hang-monitor',
   '--disable-ipc-flooding-protection',
-  '--disable-offer-store-unmasked-wallet-cards',
-  '--disable-popup-blocking',
   '--disable-print-preview',
-  '--disable-prompt-on-repost',
-  '--disable-renderer-backgrounding',
   '--disable-setuid-sandbox',
+  '--disable-site-isolation-trials',
   '--disable-speech-api',
-  '--disable-sync',
   '--disable-web-security',
   '--disk-cache-size=33554432',
   '--hide-scrollbars',
   '--ignore-gpu-blocklist',
-  '--metrics-recording-only',
+  '--in-process-gpu',
   '--mute-audio',
   '--no-default-browser-check',
   '--no-first-run',
   '--no-pings',
   '--no-sandbox',
   '--no-zygote',
-  '--password-store=basic',
-  '--use-gl=swiftshader',
-  '--use-mock-keychain',
+  '--use-angle=swiftshader',
+  '--use-gl=angle',
   '--window-size=1920,1080',
   '--single-process'
 ]

By using DEBUG=puppeteer:*, the received message is:

{
  "id": 113,
  "error": {
    "code": -32000,
    "message": "Printing failed"
  },
  "sessionId": "...session id..."
}
jordxn commented 1 year ago

I had some timeout issues when upgrading from chrome-aws-lambda to 108.0.2 where the browser would timeout in my lambda function. Same as comment above, if I added DEBUG=puppeteer:*, I got

{
    "method": "Target.targetCrashed",
    "params": {
        "targetId": "28C4FE04B1B89A602F51353B96A6CE7C",
        "status": "crashed",
        "errorCode": 133
    }
}

I overwrote the args based on what was in the original chrome-aws-lambda package and it seemed to solve my issue https://github.com/alixaxel/chrome-aws-lambda/blob/master/source/index.ts#L94. Through trial and error I found that setting '--use-gl=angle' to '--use-gl=swiftshader' fixed my issue.

So perhaps it's worth considering that flag in the default as well.

Sparticuz commented 1 year ago

https://github.com/puppeteer/puppeteer/pull/9239

Sparticuz commented 1 year ago

https://developer.chrome.com/articles/new-headless/ https://antoinevastel.com/bot%20detection/2023/02/19/new-headless-chrome.html

Sparticuz commented 1 year ago

I've refactored the args function making it much more flexible.

I've migrated to using all of puppeteer's default flags, but I also kept some of the one's we've been using. https://github.com/Sparticuz/chromium/blob/dfdd20552889472d359314596977a19733f29a98/source/index.ts#L188-L202

Most of these are self-explanitory.

I would eventually like to get ride of these ones: https://github.com/Sparticuz/chromium/blob/dfdd20552889472d359314596977a19733f29a98/source/index.ts#L216-L223

HasmH commented 9 months ago

would it be possible to have some sort of addArgs function for chromium.args as it is readonly - for easier customisability? Otherwise, is the alternative this https://github.com/GoogleChrome/chrome-launcher/blob/main/docs/chrome-flags-for-tools.md#set-preferences via some bash script as i am trying to replicate this across multiple deployment environments

Sparticuz commented 9 months ago

would it be possible to have some sort of addArgs function for chromium.args

You can use the spread operator to add more args, [...chromium.args, '--newFlag', etc...].