Update readme

This commit is contained in:
Sparticuz 2022-09-27 09:57:47 -04:00
parent 94ed7f55bd
commit a9169adc59
6 changed files with 27 additions and 192 deletions

217
README.md
View File

@ -1,48 +1,49 @@
# chrome-aws-lambda
# @sparticuz/chromium
[![@sparticuz/chrome-aws-lambda](https://img.shields.io/npm/v/@sparticuz/chrome-aws-lambda.svg?style=for-the-badge)](https://www.npmjs.com/package/@sparticuz/chrome-aws-lambda)
[![TypeScript](https://img.shields.io/npm/types/chrome-aws-lambda?style=for-the-badge)](https://www.typescriptlang.org/dt/search?search=chrome-aws-lambda)
[![Chromium](https://img.shields.io/badge/chromium-48_MB-brightgreen.svg?style=for-the-badge)](bin/)
[![@sparticuz/chromium](https://img.shields.io/npm/v/@sparticuz/chromium.svg?style=for-the-badge)](https://www.npmjs.com/package/@sparticuz/chromium)
[![TypeScript](https://img.shields.io/npm/types/chrome-aws-lambda?style=for-the-badge)](https://www.typescriptlang.org/dt/search?search=chromium)
[![Chromium](https://img.shields.io/badge/chromium-51_MB-brightgreen.svg?style=for-the-badge)](bin/)
[![Donate](https://img.shields.io/badge/donate-paypal-orange.svg?style=for-the-badge)](https://paypal.me/sparticuz)
Chromium Binary for AWS Lambda and Google Cloud Functions
## Chromium for Serverless platforms
### Difference from alixaxel/chrome-aws-lambda
This fork was born out of [alixaxel/chrome-aws-lambda#264](https://github.com/alixaxel/chrome-aws-lambda/pull/264).
This package was originally forked from [alixaxel/chrome-aws-lambda#264](https://github.com/alixaxel/chrome-aws-lambda/pull/264).
The biggest difference, besides the chromium version, is the inclusion of some code from https://github.com/alixaxel/lambdafs,
as well as dropping that as a dependency. Due to some changes in WebGL, the files in bin/swiftshader.tar.br need to
be extracted to `/tmp` instead of `/tmp/swiftshader`. This necessitated changes in lambdafs.
However, it quickly became difficult to maintain because of the pace of `puppeteer` updates. This package, `@sparticuz/chromium`,
is not chained to `puppeteer` versions. It is only `chromium`, as well as the special code needed to decompress the brotli package.
## Install
```shell
npm install @sparticuz/chrome-aws-lambda --save-prod
```
[`puppeteer` ships with a prefered version of `chromium`](https://pptr.dev/faq/#q-why-doesnt-puppeteer-vxxx-work-with-chromium-vyyy).
In order to figure out what version of `@sparticuz/chromium` you will need, please visit [Puppeteer's Chromium Support page](https://pptr.dev/chromium-support).
This will ship with appropriate binary for the latest stable release of [`puppeteer`](https://github.com/GoogleChrome/puppeteer) (usually updated within a few days).
You also need to install the corresponding version of `puppeteer-core` (or `puppeteer`):
> For example, as of today, the latest version of `puppeteer` is `18.0.5`. The latest version of `chromium` stated on `puppeteer`'s support page is `106.0.5249.0`. So you need to install `@sparticuz/chromium@106`.
```shell
npm install puppeteer-core --save-prod
# Puppeteer or Playwright is a production dependency
npm install --save puppeteer-core@$PUPPETEER_VERSION
npm install --save-dev @sparticuz/chromium@$CHROMIUM_VERSION
```
If you wish to install an older version of Chromium, take a look at [Versioning](https://github.com/Sparticuz/chrome-aws-lambda#versioning).
If you wish to install an older version of Chromium, take a look at [@sparticuz/chrome-aws-lambda](https://github.com/Sparticuz/chrome-aws-lambda#versioning) or [@alixaxel/chrome-aws-lambda](https://github.com/alixaxel/chrome-aws-lambda).
## Usage
This package works with all the currently supported AWS Lambda Node.js runtimes out of the box.
```javascript
const chromium = require('@sparticuz/chrome-aws-lambda');
const puppeteer = require("puppeteer-core");
const chromium = require('@sparticuz/chromium');
exports.handler = async (event, context, callback) => {
let result = null;
let browser = null;
try {
browser = await chromium.puppeteer.launch({
browser = await puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath,
@ -70,8 +71,8 @@ exports.handler = async (event, context, callback) => {
### Usage with Playwright
```javascript
const chromium = require('@sparticuz/chrome-aws-lambda');
const playwright = require('playwright-core');
const chromium = require('@sparticuz/chromium');
(async () => {
const browser = await playwright.chromium.launch({
@ -146,172 +147,6 @@ Afterwards, you just need to ZIP the directory and upload it as a AWS Lambda Lay
```shell
zip -9 --filesync --move --recurse-paths .fonts.zip .fonts/
```
## Overloading
Since version `8.0.0`, it's possible to [overload puppeteer](/typings/chrome-aws-lambda.d.ts) with the following convenient API:
```typescript
interface Browser {
defaultPage(...hooks: ((page: Page) => Promise<Page>)[])
newPage(...hooks: ((page: Page) => Promise<Page>)[])
}
interface BrowserContext {
defaultPage(...hooks: ((page: Page) => Promise<Page>)[])
newPage(...hooks: ((page: Page) => Promise<Page>)[])
}
interface Page {
block(patterns: string[])
clear(selector: string)
clickAndWaitForNavigation(selector: string, options?: WaitForOptions)
clickAndWaitForRequest(selector: string, predicate: string | RegExp, options?: WaitTimeoutOptions)
clickAndWaitForRequest(selector: string, predicate: ((request: HTTPRequest) => boolean | Promise<boolean>), options?: WaitTimeoutOptions)
clickAndWaitForResponse(selector: string, predicate: string | RegExp, options?: WaitTimeoutOptions)
clickAndWaitForResponse(selector: string, predicate: ((request: HTTPResponse) => boolean | Promise<boolean>), options?: WaitTimeoutOptions)
count(selector: string)
exists(selector: string)
fillFormByLabel(selector: string, data: Record<string, boolean | string | string[]>)
fillFormByName(selector: string, data: Record<string, boolean | string | string[]>)
fillFormBySelector(selector: string, data: Record<string, boolean | string | string[]>)
fillFormByXPath(selector: string, data: Record<string, boolean | string | string[]>)
number(selector: string, decimal?: string, property?: string)
selectByLabel(selector: string, ...values: string[])
string(selector: string, property?: string)
waitForInflightRequests(requests?: number, alpha: number, omega: number, options?: WaitTimeoutOptions)
waitForText(predicate: string, options?: WaitTimeoutOptions)
waitUntilVisible(selector: string, options?: WaitTimeoutOptions)
waitWhileVisible(selector: string, options?: WaitTimeoutOptions)
withTracing(options: TracingOptions, callback: (page: Page) => Promise<any>)
}
interface Frame {
clear(selector: string)
clickAndWaitForNavigation(selector: string, options?: WaitForOptions)
clickAndWaitForRequest(selector: string, predicate: string | RegExp, options?: WaitTimeoutOptions)
clickAndWaitForRequest(selector: string, predicate: ((request: HTTPRequest) => boolean | Promise<boolean>), options?: WaitTimeoutOptions)
clickAndWaitForResponse(selector: string, predicate: string | RegExp, options?: WaitTimeoutOptions)
clickAndWaitForResponse(selector: string, predicate: ((request: HTTPResponse) => boolean | Promise<boolean>), options?: WaitTimeoutOptions)
count(selector: string)
exists(selector: string)
fillFormByLabel(selector: string, data: Record<string, boolean | string | string[]>)
fillFormByName(selector: string, data: Record<string, boolean | string | string[]>)
fillFormBySelector(selector: string, data: Record<string, boolean | string | string[]>)
fillFormByXPath(selector: string, data: Record<string, boolean | string | string[]>)
number(selector: string, decimal?: string, property?: string)
selectByLabel(selector: string, ...values: string[])
string(selector: string, property?: string)
waitForText(predicate: string, options?: WaitTimeoutOptions)
waitUntilVisible(selector: string, options?: WaitTimeoutOptions)
waitWhileVisible(selector: string, options?: WaitTimeoutOptions)
}
interface ElementHandle {
clear()
clickAndWaitForNavigation(options?: WaitForOptions)
clickAndWaitForRequest(predicate: string | RegExp, options?: WaitTimeoutOptions)
clickAndWaitForRequest(predicate: ((request: HTTPRequest) => boolean | Promise<boolean>), options?: WaitTimeoutOptions)
clickAndWaitForResponse(predicate: string | RegExp, options?: WaitTimeoutOptions)
clickAndWaitForResponse(predicate: ((request: HTTPResponse) => boolean | Promise<boolean>), options?: WaitTimeoutOptions)
fillFormByLabel(data: Record<string, boolean | string | string[]>)
fillFormByName(data: Record<string, boolean | string | string[]>)
fillFormBySelector(data: Record<string, boolean | string | string[]>)
fillFormByXPath(data: Record<string, boolean | string | string[]>)
getInnerHTML()
getInnerText()
number(decimal?: string, property?: string)
selectByLabel(...values: string[])
string(property?: string)
}
```
To enable this behavior, simply call the `puppeteer` property exposed by this package.
> Refer to the [TypeScript typings](/typings/chrome-aws-lambda.d.ts) for general documentation.
## Page Hooks
When overloaded, you can specify a list of hooks to automatically apply to pages.
For instance, to remove the `Headless` substring from the user agent:
```typescript
async function replaceUserAgent(page: Page): Promise<Page> {
let value = await page.browser().userAgent();
if (value.includes('Headless') === true) {
await page.setUserAgent(value.replace('Headless', ''));
}
return page;
}
```
And then simply pass that page hook to `defaultPage()` or `newPage()`:
```typescript
let page = await browser.defaultPage(replaceUserAgent);
```
> Additional bundled page hooks can be found on [`/build/hooks`](/source/hooks).
## Versioning
This package is versioned based on the underlying `puppeteer` minor version:
| `puppeteer` Version | `chrome-aws-lambda` Version | Chromium Revision |
| ------------------- | --------------------------------------------- | ------------------------------------------------------- |
| `17.1.*` | `npm i @sparticuz/chrome-aws-lambda@~17.1.1` | [`1036745`](https://crrev.com/1036745) (`106.0.5249.0`) |
| `16.1.*` | `npm i @sparticuz/chrome-aws-lambda@~16.1.0` | [`1022525`](https://crrev.com/1011831) (`105.0.5173.0`) |
| `15.5.*` | `npm i @sparticuz/chrome-aws-lambda@~15.5.0` | [`1022525`](https://crrev.com/1011831) (`105.0.5173.0`) |
| `14.4.*` | `npm i @sparticuz/chrome-aws-lambda@~14.4.1` | [`1002410`](https://crrev.com/1002410) (`103.0.5058.0`) |
| `14.3.*` | `npm i @sparticuz/chrome-aws-lambda@~14.3.0` | [`1002410`](https://crrev.com/1002410) (`103.0.5058.0`) |
| `14.2.*` | `npm i @sparticuz/chrome-aws-lambda@~14.2.0` | [`1002410`](https://crrev.com/1002410) (`103.0.5058.0`) |
| `14.1.*` | `npm i @sparticuz/chrome-aws-lambda@~14.1.1` | [`991974`](https://crrev.com/991974) (`102.0.5002.0`) |
| `10.1.*` | `npm i chrome-aws-lambda@~10.1.0` | [`884014`](https://crrev.com/884014) (`92.0.4512.0`) |
| `10.0.*` | `npm i chrome-aws-lambda@~10.0.0` | [`884014`](https://crrev.com/884014) (`92.0.4512.0`) |
| `9.1.*` | `npm i chrome-aws-lambda@~9.1.0` | [`869685`](https://crrev.com/869685) (`91.0.4469.0`) |
| `9.0.*` | `npm i chrome-aws-lambda@~9.0.0` | [`869685`](https://crrev.com/869685) (`91.0.4469.0`) |
| `8.0.*` | `npm i chrome-aws-lambda@~8.0.2` | [`856583`](https://crrev.com/856583) (`90.0.4427.0`) |
| `7.0.*` | `npm i chrome-aws-lambda@~7.0.0` | [`848005`](https://crrev.com/848005) (`90.0.4403.0`) |
| `6.0.*` | `npm i chrome-aws-lambda@~6.0.0` | [`843427`](https://crrev.com/843427) (`89.0.4389.0`) |
| `5.5.*` | `npm i chrome-aws-lambda@~5.5.0` | [`818858`](https://crrev.com/818858) (`88.0.4298.0`) |
| `5.4.*` | `npm i chrome-aws-lambda@~5.4.0` | [`809590`](https://crrev.com/809590) (`87.0.4272.0`) |
| `5.3.*` | `npm i chrome-aws-lambda@~5.3.1` | [`800071`](https://crrev.com/800071) (`86.0.4240.0`) |
| `5.2.*` | `npm i chrome-aws-lambda@~5.2.1` | [`782078`](https://crrev.com/782078) (`85.0.4182.0`) |
| `5.1.*` | `npm i chrome-aws-lambda@~5.1.0` | [`768783`](https://crrev.com/768783) (`84.0.4147.0`) |
| `5.0.*` | `npm i chrome-aws-lambda@~5.0.0` | [`756035`](https://crrev.com/756035) (`83.0.4103.0`) |
| `3.1.*` | `npm i chrome-aws-lambda@~3.1.1` | [`756035`](https://crrev.com/756035) (`83.0.4103.0`) |
| `3.0.*` | `npm i chrome-aws-lambda@~3.0.4` | [`737027`](https://crrev.com/737027) (`81.0.4044.0`) |
| `2.1.*` | `npm i chrome-aws-lambda@~2.1.1` | [`722234`](https://crrev.com/722234) (`80.0.3987.0`) |
| `2.0.*` | `npm i chrome-aws-lambda@~2.0.2` | [`705776`](https://crrev.com/705776) (`79.0.3945.0`) |
| `1.20.*` | `npm i chrome-aws-lambda@~1.20.4` | [`686378`](https://crrev.com/686378) (`78.0.3882.0`) |
| `1.19.*` | `npm i chrome-aws-lambda@~1.19.0` | [`674921`](https://crrev.com/674921) (`77.0.3844.0`) |
| `1.18.*` | `npm i chrome-aws-lambda@~1.18.1` | [`672088`](https://crrev.com/672088) (`77.0.3835.0`) |
| `1.18.*` | `npm i chrome-aws-lambda@~1.18.0` | [`669486`](https://crrev.com/669486) (`77.0.3827.0`) |
| `1.17.*` | `npm i chrome-aws-lambda@~1.17.1` | [`662092`](https://crrev.com/662092) (`76.0.3803.0`) |
| `1.16.*` | `npm i chrome-aws-lambda@~1.16.1` | [`656675`](https://crrev.com/656675) (`76.0.3786.0`) |
| `1.15.*` | `npm i chrome-aws-lambda@~1.15.1` | [`650583`](https://crrev.com/650583) (`75.0.3765.0`) |
| `1.14.*` | `npm i chrome-aws-lambda@~1.14.0` | [`641577`](https://crrev.com/641577) (`75.0.3738.0`) |
| `1.13.*` | `npm i chrome-aws-lambda@~1.13.0` | [`637110`](https://crrev.com/637110) (`74.0.3723.0`) |
| `1.12.*` | `npm i chrome-aws-lambda@~1.12.2` | [`624492`](https://crrev.com/624492) (`73.0.3679.0`) |
| `1.11.*` | `npm i chrome-aws-lambda@~1.11.2` | [`609904`](https://crrev.com/609904) (`72.0.3618.0`) |
| `1.10.*` | `npm i chrome-aws-lambda@~1.10.1` | [`604907`](https://crrev.com/604907) (`72.0.3582.0`) |
| `1.9.*` | `npm i chrome-aws-lambda@~1.9.1` | [`594312`](https://crrev.com/594312) (`71.0.3563.0`) |
| `1.8.*` | `npm i chrome-aws-lambda@~1.8.0` | [`588429`](https://crrev.com/588429) (`71.0.3542.0`) |
| `1.7.*` | `npm i chrome-aws-lambda@~1.7.0` | [`579032`](https://crrev.com/579032) (`70.0.3508.0`) |
| `1.6.*` | `npm i chrome-aws-lambda@~1.6.3` | [`575458`](https://crrev.com/575458) (`69.0.3494.0`) |
| `1.5.*` | `npm i chrome-aws-lambda@~1.5.0` | [`564778`](https://crrev.com/564778) (`69.0.3452.0`) |
| `1.4.*` | `npm i chrome-aws-lambda@~1.4.0` | [`555668`](https://crrev.com/555668) (`68.0.3419.0`) |
| `1.3.*` | `npm i chrome-aws-lambda@~1.3.0` | [`549031`](https://crrev.com/549031) (`67.0.3391.0`) |
| `1.2.*` | `npm i chrome-aws-lambda@~1.2.0` | [`543305`](https://crrev.com/543305) (`67.0.3372.0`) |
| `1.1.*` | `npm i chrome-aws-lambda@~1.1.0` | [`536395`](https://crrev.com/536395) (`66.0.3347.0`) |
| `1.0.*` | `npm i chrome-aws-lambda@~1.0.0` | [`526987`](https://crrev.com/526987) (`65.0.3312.0`) |
| `0.13.*` | `npm i chrome-aws-lambda@~0.13.0` | [`515411`](https://crrev.com/515411) (`64.0.3264.0`) |
Patch versions are reserved for bug fixes in `chrome-aws-lambda` and general maintenance.
## Compiling
To compile your own version of Chromium check the [Ansible playbook instructions](_/ansible).
@ -320,17 +155,17 @@ To compile your own version of Chromium check the [Ansible playbook instructions
[Lambda Layers](https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html) is a new convenient way to manage common dependencies between different Lambda Functions.
The following set of (Linux) commands will create a layer of this package alongside `puppeteer-core`:
The following set of (Linux) commands will create a layer of this package:
```shell
git clone --depth=1 https://github.com/alixaxel/chrome-aws-lambda.git && \
cd chrome-aws-lambda && \
make chrome_aws_lambda.zip
git clone --depth=1 https://github.com/sparticuz/chromium.git && \
cd chromium && \
make chromium.zip
```
The above will create a `chrome-aws-lambda.zip` file, which can be uploaded to your Layers console.
The above will create a `chromium.zip` file, which can be uploaded to your Layers console.
Alternatively, you can also download the layer artifact from one of our [CI workflow runs](https://github.com/Sparticuz/chrome-aws-lambda/actions/workflows/aws.yml?query=is%3Asuccess+branch%3Amaster).
Alternatively, you can also download the layer artifact from one of our [CI workflow runs](https://github.com/Sparticuz/chromium/actions/workflows/aws.yml?query=is%3Asuccess+branch%3Amaster).
## Google Cloud Functions

0
_/ansible/ansible.cfg Normal file → Executable file
View File

View File

@ -14,4 +14,4 @@ instance_size=c6a.8xlarge
ansible_connection=ssh
ansible_python_interpreter=auto_silent
ansible_ssh_private_key_file=ansible.pem
puppeteer_version=v17.1.3
puppeteer_version=v18.0.5

0
bin/chromium.br Normal file → Executable file
View File

0
bin/swiftshader.tar.br Normal file → Executable file
View File

0
incrementVersion Normal file → Executable file
View File