Update readme

This commit is contained in:
Sparticuz 2023-01-13 14:55:41 -05:00
parent 71d4abf4a3
commit 4fb4a6f17d
1 changed files with 43 additions and 22 deletions

View File

@ -87,14 +87,26 @@ test("Check the page title of example.com", async (t) => {
assert.strictEqual(pageTitle, "Example Domain"); assert.strictEqual(pageTitle, "Example Domain");
}); });
``` ```
You should allocate at least 512 MB of RAM to your Lambda, however 1600 MB (or more) is recommended.
You can also specify a custom Chromium location as following. ### -min package
The -min package DOES NOT include the chromium brotli files. There are a few instances where this
is useful. Primarily, this is useful when you have file size limits.
To use the -min package please install the `@sparticuz/chromium-min` package.
When using the -min package, you need to specify the location of the brotli files.
In this example, /opt/chromium contains all the brotli files
```
/opt
/chromium
/aws.tar.br
/chromium.br
/swiftshader.tar.br
```
```javascript ```javascript
const test = require("node:test");
const puppeteer = require("puppeteer-core");
const chromium = require("@sparticuz/chromium");
test("Check the page title of example.com", async (t) => {
const browser = await puppeteer.launch({ const browser = await puppeteer.launch({
args: chromium.args, args: chromium.args,
defaultViewport: chromium.defaultViewport, defaultViewport: chromium.defaultViewport,
@ -102,18 +114,27 @@ test("Check the page title of example.com", async (t) => {
headless: chromium.headless, headless: chromium.headless,
ignoreHTTPSErrors: true, ignoreHTTPSErrors: true,
}); });
```
In the following example, https://www.example.com/chromiumPack.tar contains all the brotli files.
Generally, this would be a location on S3, or another very fast downloadable location,
that is close to your function's execution location.
const page = await browser.newPage(); @sparticuz/chromium will download the pack tar file, untar the files to /tmp/chromium-pack,
await page.goto("https://example.com"); then will un-brotli the files to /tmp/chromium. The next iteration will have /tmp/chromium exist
const pageTitle = await page.title(); and will use the already downloaded files.
await browser.close();
assert.strictEqual(pageTitle, "Example Domain"); The latest chromium-pack.tar file will be on the latest [release](https://github.com/Sparticuz/chromium/releases).
```javascript
const browser = await puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath("https://www.example.com/chromiumPack.tar"),
headless: chromium.headless,
ignoreHTTPSErrors: true,
}); });
``` ```
You should allocate at least 512 MB of RAM to your Lambda, however 1600 MB (or more) is recommended.
### Running Locally ### Running Locally
This package will run in headless mode when `NODE_ENV = "test"`. If you want to run using your own local binary, set `IS_LOCAL` to anything. This package will run in headless mode when `NODE_ENV = "test"`. If you want to run using your own local binary, set `IS_LOCAL` to anything.
@ -195,7 +216,7 @@ aws s3 cp chromium.zip "s3://${bucketName}/chromiumLayers/chromium${versionNumbe
aws lambda publish-layer-version --layer-name chromium --description "Chromium v${versionNumber}" --content "S3Bucket=${bucketName},S3Key=chromiumLayers/chromium${versionNumber}.zip" --compatible-runtimes nodejs --compatible-architectures x86_64 aws lambda publish-layer-version --layer-name chromium --description "Chromium v${versionNumber}" --content "S3Bucket=${bucketName},S3Key=chromiumLayers/chromium${versionNumber}.zip" --compatible-runtimes nodejs --compatible-architectures x86_64
``` ```
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). Use the `chromium.zip` INSIDE the artifact as the layer. Also, the artifact will expire from Github after a certain time period. Alternatively, you can also download the layer artifact from one of our [releases](https://github.com/Sparticuz/chromium/releases).
According to our benchmarks, it's 40% to 50% faster than using the off-the-shelf `puppeteer` bundle. According to our benchmarks, it's 40% to 50% faster than using the off-the-shelf `puppeteer` bundle.