alixaxel / chrome-aws-lambda

Chromium Binary for AWS Lambda and Google Cloud Functions
MIT License
3.17k stars 289 forks source link

Puppeteer@14.1.0 #264

Open Sparticuz opened 2 years ago

Sparticuz commented 2 years ago

This PR updates the build process for chromium and gets puppeteer support up to 14.1.0.

Closes: #240 #248 #258 #254 #242 #274 #275 #276

Notes:

Due to some changes in WebGL/SWAngle, this PR does not included the needed fixes for lambdafs. If you need WebGL, please use my scoped package.

aeristhy commented 2 years ago

@Sparticuz Hi there, is there anyway to implement this on my codes/dep without manually copy pasting? Should i make a private npm package using this pr?

Sparticuz commented 2 years ago

@aeristhy

If you would like to use a scoped npm package that will be kept up to date until this PR is merged, check out @sparticuz/chrome-aws-lambda

bjassael commented 2 years ago

@Sparticuz thanks for the PR. After updating my code to use these changes there is a drop in performance when taking screenshots with Puppeteer in AWS (from '< 1' to '~8' seconds). Also, total memory consumption almost double from ~450mb to ~800mb. Any clue of what could have trigger this problem or possible fixes?

Sparticuz commented 2 years ago

After updating my code to use these changes there is a drop in performance

Are you using this PR or my fork? This branch does not have the updated swiftshader code, so chromium is likely searching for the right files and not finding them. I believe someone further up had similar problems.

I'm still trying to figure out how to update this PR with the needed changes.

My fork includes the needed changes to get webgl working.

That would be my guess, but I haven't measured anything.

bjassael commented 2 years ago

Sorry, I didn't specified, I'm using the fork. So it does have the webGL changes.

codykaup commented 2 years ago

Thanks for putting this together! I tried using the binary from your v14.3.0 branch with Playwright v1.22.2 but I keep getting the following error whenever I try to create a new page:

[err] [ERROR:file_path_watcher_inotify.cc(329)] inotify_init() failed: Function not implemented (38)
[err] Received signal 11 SEGV_MAPERR XXXXXXXXXXXXX

Is anybody else hitting this? Am I doing something wrong?

Antoine-C commented 2 years ago

@codykaup I had the same error when using Lambda docker image on Apple M1, you need to add the --platform linux/amd64 in order to get rid of this error 👍

Antoine-C commented 2 years ago

@Sparticuz I can confirm the issue @bjassael is having with performance degradation with the WebGL fix, I can see screenshots being 10x slower (I see numbers going from 150ms to 1.2s+). Maybe using angle with swiftshader is causing this degradation given without the webgl fix it was not using swiftshader libs right ?

codykaup commented 2 years ago

Thanks for the heads up @Antoine-C, it's working locally now!

I tried running this in Lambda but it throws a different error for some reason. I tried multiple versions (v14.1.0, v14.1.1, and v14.3.0) but all of them throw this same error. Any ideas on why the binaries from @Sparticuz's fork does this with Playwright?

browser.newPage: Browser closed.
==================== Browser output: ====================
<launching> /tmp/chromium --disable-field-trial-config --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --headless --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --allow-running-insecure-content --autoplay-policy=user-gesture-required --disable-component-update --disable-domain-reliability --disable-features=AudioServiceOutOfProcess,IsolateOrigins,site-per-process --disable-print-preview --disable-setuid-sandbox --disable-site-isolation-trials --disable-speech-api --disable-web-security --disk-cache-size=33554432 --enable-features=SharedArrayBuffer --hide-scrollbars --ignore-gpu-blocklist --in-process-gpu --mute-audio --no-default-browser-check --no-pings --no-sandbox --no-zygote --use-gl=angle --use-angle=swiftshader --window-size=1920,1080 --single-process --font-render-hinting=slight --user-data-dir=/tmp/playwright_chromiumdev_profile-W8GLWJ --remote-debugging-pipe --no-startup-window
<launched> pid=476
[pid=476][err] Received signal 11 SEGV_MAPERR 0000000000b0
[pid=476][err] #0 0x5604b9191cb9 (/tmp/chromium+0x5938cb8)
[pid=476][err] #1 0x5604b9118af3 (/tmp/chromium+0x58bfaf2)
[pid=476][err] #2 0x5604b91917c1 (/tmp/chromium+0x59387c0)
[pid=476][err] #3 0x7fc617d898e0 (/usr/lib64/libpthread-2.26.so+0x118df)
[pid=476][err] #4 0x5604b7d6610a (/tmp/chromium+0x450d109)
[pid=476][err] #5 0x5604b7d65189 (/tmp/chromium+0x450c188)
[pid=476][err] #6 0x5604b7d9fb14 (/tmp/chromium+0x4546b13)
[pid=476][err] #7 0x5604b7d9f90e (/tmp/chromium+0x454690d)
[pid=476][err] #8 0x5604b7cbf8df (/tmp/chromium+0x44668de)
[pid=476][err] #9 0x5604b7ed846d (/tmp/chromium+0x467f46c)
[pid=476][err] #10 0x5604b7ecc5f6 (/tmp/chromium+0x46735f5)
[pid=476][err] #11 0x5604b90f8f9e (/tmp/chromium+0x589ff9d)
[pid=476][err] #12 0x5604bcdfcb18 (/tmp/chromium+0x95a3b17)
[pid=476][err] #13 0x5604bce06ce3 (/tmp/chromium+0x95adce2)
[pid=476][err] #14 0x5604bce06e49 (/tmp/chromium+0x95ade48)
[pid=476][err] #15 0x5604bce0d0c9 (/tmp/chromium+0x95b40c8)
[pid=476][err] #16 0x5604b8978a03 (/tmp/chromium+0x511fa02)
[pid=476][err] #17 0x5604bce04418 (/tmp/chromium+0x95ab417)
[pid=476][err] #18 0x5604bce020b8 (/tmp/chromium+0x95a90b7)
[pid=476][err] #19 0x5604b7a5b98e (/tmp/chromium+0x420298d)
[pid=476][err] #20 0x5604b7a5b37a (/tmp/chromium+0x4202379)
[pid=476][err] #21 0x5604b7a57622 (/tmp/chromium+0x41fe621)
[pid=476][err] #22 0x5604b9151c50 (/tmp/chromium+0x58f8c4f)
[pid=476][err] #23 0x5604b9165a20 (/tmp/chromium+0x590ca1f)
[pid=476][err] #24 0x5604b916572c (/tmp/chromium+0x590c72b)
[pid=476][err] #25 0x5604b9165fa2 (/tmp/chromium+0x590cfa1)
[pid=476][err] #26 0x5604b91aefcb (/tmp/chromium+0x5955fca)
[pid=476][err] #27 0x5604b9166226 (/tmp/chromium+0x590d225)
[pid=476][err] #28 0x5604b91391ed (/tmp/chromium+0x58e01ec)
[pid=476][err] #29 0x5604b79d588d (/tmp/chromium+0x417c88c)
[pid=476][err] #30 0x5604b79d6ed2 (/tmp/chromium+0x417ded1)
[pid=476][err] #31 0x5604b90fc4ce (/tmp/chromium+0x58a34cd)
[pid=476][err] #32 0x5604b812adb2 (/tmp/chromium+0x48d1db1)
[pid=476][err] #33 0x5604b812bfde (/tmp/chromium+0x48d2fdd)
[pid=476][err] #34 0x5604b812bb6f (/tmp/chromium+0x48d2b6e)
[pid=476][err] #35 0x5604b812915e (/tmp/chromium+0x48d015d)
[pid=476][err] #36 0x5604b8129b1e (/tmp/chromium+0x48d0b1d)
[pid=476][err] #37 0x5604b90f88ba (/tmp/chromium+0x589f8b9)
[pid=476][err] #38 0x5604b90f85e5 (/tmp/chromium+0x589f5e4)
[pid=476][err] #39 0x7fc61725c13a __libc_start_main
[pid=476][err] #40 0x5604b68a602a _start
[pid=476][err] r8: 0000000000000010 r9: 0000000000000000 r10: 0000000000000000 r11: 0000000000000246
[pid=476][err] r12: 00007ffedd13c800 r13: 0000173400edf0b8 r14: 0000173400edf930 r15: 00007ffedd13c7d0
[pid=476][err] di: 00001734002e4000 si: 0000000000000000 bp: 00007ffedd13c840 bx: 0000173400ede800
[pid=476][err] dx: d015f40034170000 ax: 00001734002e4000 cx: 0000000000000000 sp: 00007ffedd13c770
[pid=476][err] ip: 00005604b7d6610a efl: 0000000000010246 cgf: 002b000000000033 erf: 0000000000000004
[pid=476][err] trp: 000000000000000e msk: 0000000000000000 cr2: 00000000000000b0
[pid=476][err] [end of stack trace]
jznadams commented 2 years ago

I had the same error when using Lambda docker image on Apple M1, you need to add the --platform linux/amd64 in order to get rid of this error 👍

@Antoine-C Where do you add that flag?

rehanvdm commented 2 years ago

I'm wondering if it might not be better to run puppeteer in a container now that Lambda supports it? This PR has been open and struggling for months now :( or will the same issues be present running it in a container?

PS. I am currently running this on a Lambda in production and don't want to go the container route.

Antoine-C commented 2 years ago

I had the same error when using Lambda docker image on Apple M1, you need to add the --platform linux/amd64 in order to get rid of this error 👍

@Antoine-C Where do you add that flag?

In your Dockerfile next to the FROM statement or as a parameter when using docker run command

Sparticuz commented 2 years ago

Any ideas on why the binaries from @Sparticuz's fork does this with Playwright?

I haven't used Playwright, but I also haven't changed anything that would affect it.

For people seeing slowness, does turning webgl off help? This may just be related to the new driver. If someone is running x-ray on their function, I'd love to see any info about what exactly is slow.

yakirza17 commented 2 years ago

Hi @Sparticuz, I make tests for the page.screenshot issue and these are the numbers:

Puppeteer 14.3 with WebGL (based your repo, on tag v14.3.0, not contains the PR of decrease chrome size): avg(duration): 1775.1579 min(duration): 485 max(duration): 15519 count(duration): 3693

Old puppeteer version (5.5, without this PR): avg(duration): 275.1661 min(duration): 22 max(duration): 5097 count(duration): 3649

Puppeteer 14.3 without WebGL (--disable-webgl and remove --use-gl=angle, --use-angle=swiftshader): avg(duration): 732.9199 min(duration): 283 max(duration): 5977 count(duration): 3672

Sparticuz commented 2 years ago

My guess on the slowness would just be from Chrome's version creep? Those numbers are interesting @yakirza17, however, I'm looking more for a nodejs firegraph that could tell us whether the slowdown is occurring in chrome_aws_lambda, puppeteer, or chromium. FWIW, I really haven't changed any chrome_aws_lambda code besides the patch making it compatible with node16 and ts4.4+.

Edit: Puppeteer 5.5 is Chromium 88, Puppeteer 14.3 is Chromium 103. That being said, I would recommend running with webgl disabled if you don't need it.

Antoine-C commented 2 years ago

@Sparticuz I was able to run 0x in a Lambda docker container and the flamegraph doesn't show any unoptimized bits regarding the screenshot in playwright nor chrome_aws_lambda so IMO the slowdown is coming from chromium.

When I was using swiftshader directly --use-gl=swiftshader with chromium 99 I was already experiencing a slowness regarding the screenshots. Moving to --use-gl=angle --use-angle=swiftshader fixed it but the WebGL issue came up and it was, as you said, because swiftshader libs where not at the right place and then the slowness appeared again so I'm thinking Swiftshader with chromium 95+ might not be the right choice to use for headless (or maybe it's broken) ?

I came up across these possible flags for ANGLE : https://chromium.googlesource.com/angle/angle/+/main/doc/DebuggingTips.md, I don't have much knowledge here but do you think it's possible to use another renderer like Vulkan (given we're including some vk_* files) ? Or swiftshader is the only way to go ?

Sparticuz commented 2 years ago

Sorry all, I'm out of the country at the moment. I will update to the latest puppeteer next week.

Antoine-C commented 2 years ago

@Sparticuz No worries, have you had the chance to look at it ? On my end I've noticed quite some "Browser closed" errors with [pid=348][err] [0626/041651.533068:ERROR:egl_util.cc(74)] Failed to load GLES library: /tmp/playwright/libGLESv2.so: /tmp/playwright/libGLESv2.so: cannot open shared object file: No such file or directory but this is linked to the issue above with WebGL and files not being in the right place but causing an unexpected slowness if they are.

Sparticuz commented 1 year ago

Hello all, I've made a new package that breaks the link between puppeteer and chrome-aws-lambda.

@sparticuz/chromium no longer needs to be in lock-step with puppeteer. Try it out here

willianfalbo commented 1 year ago

It works for me @Sparticuz 🤘🏼