RafalWilinski / serverless-puppeteer-layers

Serverless Framework + AWS Lambda Layers + Puppeteer = ❤️
https://dynobase.com
274 stars 36 forks source link

Chromium Version of the built headless_shell? #6

Closed pwagener closed 5 years ago

pwagener commented 5 years ago

I'm struggling to move beyond the basic demo shown here, and I believe it's because I'm unsure what version of Chromium the built headless_shell file came from.

I have a similar lambda that creates screenshots just fine, but I'm working on a project that uses some more advanced features of Puppeteer. One piece of my code is doing this:

...
        await page.exposeFunction('getPageData', async () => {
            debugLog(`Providing page data: ${JSON.stringify(pageData)}`);
            return pageData;
        });
...

Running the code to interact with locally-installed Chrome works great. When run in the Lambda, that call to exposeFunction produces an error:

 Protocol error (Runtime.addBinding): 'Runtime.addBinding' wasn't found)

A quick search turns up several issues in the Puppeteer project (sample one, sample two). In all cases the Puppeteer developers point to this FAQ entry ...

Q: Why doesn’t Puppeteer v.XXX work with Chromium v.YYY?

... which suggests ensuring the version of Puppeteer is aligned with the version of Chromium in use.

So, where did this particular headless_shell come from, and do you happen to know the exact version of Chromium it came from?

pwagener commented 5 years ago

I spent a bit of time poking around at this and found a reasonable way to determine it:

  1. Fire up an EC2 instance with the right AMI
  2. Copy the headless_shell up to the EC2 instance
  3. Set up an SSH tunnel with port forwarding 9222 to my local machine
  4. Run headless_shell with the debugging: ./headless_shell --remote-debugging-port=9222 --no-sandbox --disable-gpu
  5. Navigate local chrome to http://localhost:9222
  6. From the console, print out navigator.appVersion

Pretty round-about way to do it, but it works. In hindsight I could've just evaluated navigator.appVersion in the Lambda itself and that probably would've been fine. Anywhoo, it reports itself as:

"5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/67.0.3361.0 Safari/537.36"

According to the Puppeteer Releases, Chromium version 67.0.3361.0 would fall somewhere between Puppeter v1.1.0 (released with Chromium 66.0.3348.0) and v1.2.0 (released with Chromium 67.0.3372.0).

I'll give my particular project a go with Puppeteer 1.2, but I expect that to be a challenge. Might end up building my own with the current release of Puppeteer. I'll report back to this thread on progress.

lehno commented 5 years ago

if you have the latest headless_shell, share with us. We are getting printing rendering problems with this actual version and chrome 71 it does not happen

fartbagxp commented 5 years ago

I was looking at another serverless puppeteer layers repository: https://github.com/alixaxel/chrome-aws-lambda

That repo seems to have a list of versions compatible with puppeteer.

Here's a set of instructions that alixaxel provided to build your own chrome version using ansible: https://github.com/alixaxel/chrome-aws-lambda/tree/master/_/ansible

RafalWilinski commented 5 years ago

Closed in https://github.com/RafalWilinski/serverless-puppeteer-layers/pull/10