Compare commits

..

100 Commits

Author SHA1 Message Date
Sparticuz cd113882ea 130.0.0 2024-10-17 12:45:36 -04:00
Kyle McNally f664837067
Merge pull request #310 from Sparticuz/chromium/130 2024-10-17 12:40:34 -04:00
Kyle McNally 1dbbfc7ac4 Add chromium 130 2024-10-17 12:36:02 -04:00
Sparticuz dfd47f4102 129.0.0 2024-10-04 12:09:12 -04:00
Kyle McNally 540387d11a
Merge pull request #306 from Sparticuz/chromium/129 2024-10-04 12:04:40 -04:00
Kyle McNally a64b8612f6 Update chromium to 129 2024-10-04 11:53:55 -04:00
Kyle McNally c031905fbf Update package deps 2024-10-04 11:53:33 -04:00
Sparticuz 517b6c43a4 127.0.0 2024-08-19 16:11:13 -04:00
Kyle McNally f9f32ca64c
Merge pull request #290 from Sparticuz/chromium/127 2024-08-19 16:09:26 -04:00
Kyle McNally 2f7267da42 Update deps 2024-08-19 16:01:01 -04:00
Kyle McNally b580ec7aae Chromium 127 2024-08-19 16:00:50 -04:00
Kyle McNally 58613272ad Puppeteer updates for tests 2024-08-19 15:59:14 -04:00
Sparticuz 8028819dfe 126.0.0 2024-07-16 11:18:59 -04:00
Kyle McNally 995bc5a604
Merge pull request #284 from Sparticuz/chromium/126 2024-07-16 11:17:57 -04:00
Kyle McNally c51ae58407 don't disable the graphics stack https://github.com/Sparticuz/chromium/issues/247 2024-07-16 11:08:53 -04:00
Kyle McNally 2c715c4e97 update to chromium 126 2024-07-16 11:06:49 -04:00
Kyle McNally 2bcd54a6c8 ignore internal docker folder 2024-07-16 11:05:49 -04:00
Kyle McNally bd9c5e9014 update deps 2024-07-16 11:05:35 -04:00
Sparticuz 3e6aa79fb8 123.0.1 2024-04-04 09:41:54 -04:00
Kyle McNally d0543e6139
Merge pull request #252 from Sparticuz/fix/misc-fixes 2024-04-04 09:40:25 -04:00
Kyle McNally 41223a10e9 Disable turning off accelerated graphics
https://github.com/Sparticuz/chromium/issues/247
2024-04-03 14:42:23 -04:00
Kyle McNally e4de013045 update deps 2024-04-03 13:27:08 -04:00
Kyle McNally 4ce60bdd4d more info on closing chromium 2024-04-03 13:07:27 -04:00
Kyle McNally 0f12e5f2d7 closes #113 2024-04-03 11:33:02 -04:00
Kyle McNally 94b8687686 closes #148 2024-04-03 11:23:54 -04:00
Sparticuz bb952358a2 123.0.0 2024-03-20 14:34:18 -04:00
Kyle McNally 2c5dabf81b
Merge pull request #241 from Sparticuz/chromium/123 2024-03-20 14:32:30 -04:00
Kyle McNally c0b12ce7be Update deps 2024-03-20 14:23:49 -04:00
Kyle McNally ce553320d8 Fix types 2024-03-20 14:23:39 -04:00
Kyle McNally c640690f16 Update to 123.0.6312.0 2024-03-20 14:23:18 -04:00
Sparticuz 8efe5f9145 122.0.0 2024-02-22 12:20:04 -05:00
Kyle McNally aaa9fa63d0
Merge pull request #228 from Sparticuz/dependabot/github_actions/ncipollo/release-action-1.14.0 2024-02-22 12:19:06 -05:00
Kyle McNally 800c97f871
Merge branch 'master' into dependabot/github_actions/ncipollo/release-action-1.14.0 2024-02-22 12:13:44 -05:00
Kyle McNally 1da7ed4b19
Merge pull request #233 from Sparticuz/chromium122 2024-02-22 12:11:51 -05:00
Kyle McNally 918c7ffe9e notes about headless version 2024-02-22 12:07:10 -05:00
Kyle McNally 01c4850279 Update screenshot sha's due to disabling font-hinting 2024-02-22 12:00:48 -05:00
Kyle McNally 9a6247d0e3 Chromium 122 2024-02-22 11:55:32 -05:00
Kyle McNally da5037292d Breaking: update puppeteer dep
Old mode is now "chrome-headless-shell", which is now the default as the binary we build doesn't include support for the new headless mode.
2024-02-22 11:54:58 -05:00
Sparticuz 8206092f26 possible fix for fonts not rendering correctly 2024-02-22 08:59:09 -05:00
Sparticuz 81f83bbd65 Update deps 2024-02-22 08:58:48 -05:00
dependabot[bot] 986fca4ff3
Bump ncipollo/release-action from 1.13.0 to 1.14.0
Bumps [ncipollo/release-action](https://github.com/ncipollo/release-action) from 1.13.0 to 1.14.0.
- [Release notes](https://github.com/ncipollo/release-action/releases)
- [Commits](https://github.com/ncipollo/release-action/compare/v1.13.0...v1.14.0)

---
updated-dependencies:
- dependency-name: ncipollo/release-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-02-12 09:46:38 +00:00
Sparticuz 6e07eb0d63 121.0.0 2024-01-29 12:53:21 -05:00
Kyle McNally 857ae08500
Merge pull request #224 from Sparticuz/chromium/121 2024-01-29 12:52:57 -05:00
Sparticuz 424f3e9058 fix .fonts, add fonts 2024-01-29 12:50:10 -05:00
Sparticuz 85db6ca4e2 Merge branch 'master' into chromium/121
* master:
  Update font layer description on README for v119.0.2+
  Update SAM example to v119; fix readme link
2024-01-29 12:49:04 -05:00
Sparticuz 0f93a89596 fix permissions for chromium 2024-01-29 12:48:40 -05:00
Kyle McNally 68f6d4858f fix font directory, fixes #213, fixes #207 2024-01-29 12:41:59 -05:00
Kyle McNally 590f35ee6e update chromium to 121 2024-01-29 12:40:52 -05:00
Kyle McNally 24fa1a2210 update dependencies 2024-01-29 12:40:16 -05:00
Kyle McNally 30743fd482
Merge pull request #183 from davidjb/docs-fix 2024-01-29 10:31:17 -05:00
Kyle McNally 29004cbb13
Merge pull request #213 from fukayatsu/fukayatsu-patch-1 2024-01-29 10:23:37 -05:00
Atsuo Fukaya b5766d628b
Update font layer description on README for v119.0.2+
Use fonts instead of .fonts for v119.0.2+
2024-01-08 11:47:20 +09:00
Sparticuz 031b2d8bc4 119.0.2 2023-12-19 10:21:55 -05:00
Kyle McNally 247f748834
Merge pull request #187 from Sparticuz/fix/lambda-node20.x
Node 20 lambda support,
fixes new AL2 lambda libs
2023-12-19 10:20:41 -05:00
Sparticuz 849e769e78 update gh action setup-python dependency 2023-12-18 17:26:58 -05:00
Kyle McNally a93aa49c50 update dependencies for testing 2023-12-18 16:03:12 -05:00
Kyle McNally 05d4445708 drop console logs 2023-12-18 15:45:59 -05:00
Kyle McNally 2f52e9a534 al2 libs copied from ami-018ba43095ff50d08 2023-12-18 15:45:46 -05:00
Kyle McNally 7cfd79de38 al2023 libs copies from ami-0230bd60aa48260c6 2023-12-18 15:45:30 -05:00
Kyle McNally e5334713e3 split more al2 and al2023, change name from aws to al2 2023-12-18 15:24:50 -05:00
Sparticuz 6dba931a9a update dependencies 2023-12-18 14:22:04 -05:00
Kyle McNally 80cf8e79ce make sure the AL2023 stuff comes first! 2023-12-18 14:19:25 -05:00
Kyle McNally 62b5d05260 extract the font file 2023-12-18 14:19:06 -05:00
Kyle McNally 5597e45f59 Update screenshot sha's because of the font update 2023-12-18 14:18:22 -05:00
Kyle McNally 2b5ff55015 add debugging 2023-12-18 14:18:06 -05:00
Kyle McNally f52f2c825c update nss in al2023 2023-12-18 14:17:40 -05:00
Kyle McNally 3f02dfe58e split fonts and aws tar files, updates open sans to 3.0.0.3 2023-12-18 14:17:20 -05:00
Sparticuz cdf28b5a76 update deps 2023-12-11 09:28:21 -05:00
Sparticuz 49c1b7671c update al2023 to include nss-softokn-freebl 2023-12-11 09:22:23 -05:00
Sparticuz ec5856facc 119.0.1-next.0 2023-11-30 13:37:33 -05:00
Kyle McNally 2578196d06 update deps 2023-11-21 10:00:11 -05:00
Kyle McNally dc23b5d6ed no . in file name? 2023-11-20 16:27:39 -05:00
Sparticuz fc6b69d653 remove regex 2023-11-16 12:52:30 -05:00
Sparticuz c683d75545 includes not contains... 2023-11-16 12:46:16 -05:00
Sparticuz 6fe1820833 use contains on AWS_EXECUTION_ENV 2023-11-16 12:44:56 -05:00
Sparticuz 1b84efe984 change to use AWS_LAMBDA_JS_RUNTIME 2023-11-16 12:38:19 -05:00
Sparticuz 28b086cee9 only add the al2023 stuff on node 20 2023-11-16 12:33:04 -05:00
Sparticuz b6817b6bac add node20 lambda support 2023-11-16 12:14:09 -05:00
David Beitey b8a1c5f2c0 Update SAM example to v119; fix readme link 2023-11-14 09:13:30 +10:00
Sparticuz d63a8efc0d 119.0.0 2023-11-13 16:04:04 -05:00
Kyle McNally ad676965b2
Merge pull request #182 from Sparticuz/feature/119 2023-11-13 15:59:40 -05:00
Sparticuz 438c79c490 add 119 2023-11-13 12:50:18 -05:00
Kyle McNally 46b552d4a3
Merge pull request #179 from Sparticuz/dependabot/npm_and_yarn/types/node-18.18.9 2023-11-13 10:23:28 -05:00
Kyle McNally 057856d4af
Merge pull request #180 from Sparticuz/dependabot/npm_and_yarn/types/follow-redirects-1.14.4 2023-11-13 10:23:01 -05:00
Kyle McNally 4f485287b4
Merge pull request #181 from Sparticuz/dependabot/npm_and_yarn/types/tar-fs-2.0.4 2023-11-13 10:22:45 -05:00
Kyle McNally 8fdbb07701
Merge pull request #178 from davidjb/aws-sam-example 2023-11-13 10:22:19 -05:00
dependabot[bot] 4f8549ce5b
Bump @types/tar-fs from 2.0.3 to 2.0.4
Bumps [@types/tar-fs](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/tar-fs) from 2.0.3 to 2.0.4.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/tar-fs)

---
updated-dependencies:
- dependency-name: "@types/tar-fs"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-13 09:09:06 +00:00
dependabot[bot] 1c43eae4d7
Bump @types/follow-redirects from 1.14.3 to 1.14.4
Bumps [@types/follow-redirects](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/follow-redirects) from 1.14.3 to 1.14.4.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/follow-redirects)

---
updated-dependencies:
- dependency-name: "@types/follow-redirects"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-13 09:08:59 +00:00
dependabot[bot] bcdd0e5ad0
Bump @types/node from 18.18.7 to 18.18.9
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 18.18.7 to 18.18.9.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

---
updated-dependencies:
- dependency-name: "@types/node"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-13 09:08:50 +00:00
David Beitey e77f679a6b Add AWS SAM LayerVersion example 2023-11-13 18:59:57 +10:00
Kyle McNally 8a39891caa
Merge pull request #170 from Sparticuz/dependabot/npm_and_yarn/types/node-18.18.7
Bump @types/node from 18.18.6 to 18.18.7
2023-11-01 06:45:01 -04:00
Kyle McNally 339cbe0e19
Merge pull request #171 from Sparticuz/dependabot/github_actions/actions/setup-node-4
Bump actions/setup-node from 3 to 4
2023-11-01 06:44:45 -04:00
dependabot[bot] 18c8adb646
Bump actions/setup-node from 3 to 4
Bumps [actions/setup-node](https://github.com/actions/setup-node) from 3 to 4.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](https://github.com/actions/setup-node/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/setup-node
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-30 09:52:09 +00:00
dependabot[bot] b91a150173
Bump @types/node from 18.18.6 to 18.18.7
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 18.18.6 to 18.18.7.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

---
updated-dependencies:
- dependency-name: "@types/node"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-30 09:23:51 +00:00
Sparticuz 693a7f4abd 118.0.0 2023-10-23 12:38:01 -04:00
Kyle McNally 3a22d405ce
Merge pull request #168 from Sparticuz/feature/118 2023-10-23 12:34:35 -04:00
Kyle McNally 9b25726538
Merge pull request #143 from Sparticuz/dependabot/github_actions/ncipollo/release-action-1.13.0 2023-10-23 12:33:42 -04:00
Kyle McNally edd4995bdf
Merge pull request #156 from Sparticuz/dependabot/github_actions/actions/checkout-4 2023-10-23 12:33:22 -04:00
dependabot[bot] 1c2e225f14
Bump actions/checkout from 3 to 4
Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-11 09:18:54 +00:00
dependabot[bot] 8ec8c6edbe
Bump ncipollo/release-action from 1.12.0 to 1.13.0
Bumps [ncipollo/release-action](https://github.com/ncipollo/release-action) from 1.12.0 to 1.13.0.
- [Release notes](https://github.com/ncipollo/release-action/releases)
- [Commits](https://github.com/ncipollo/release-action/compare/v1.12.0...v1.13.0)

---
updated-dependencies:
- dependency-name: ncipollo/release-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-08-28 09:37:12 +00:00
29 changed files with 392 additions and 140 deletions

View File

@ -12,12 +12,12 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v4
- name: Setup Node.js - name: Setup Node.js
uses: actions/setup-node@v3 uses: actions/setup-node@v4
with: with:
node-version: 18.x node-version: 20.x
- name: Install Packages - name: Install Packages
run: npm ci run: npm ci
@ -29,7 +29,7 @@ jobs:
run: make chromium.zip run: make chromium.zip
- name: Upload Layer Artifact - name: Upload Layer Artifact
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v4
with: with:
name: chromium name: chromium
path: chromium.zip path: chromium.zip
@ -45,12 +45,13 @@ jobs:
version: version:
- 16 - 16
- 18 - 18
- 20
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v4
- name: Setup Python - name: Setup Python
uses: actions/setup-python@v4 uses: actions/setup-python@v5
with: with:
python-version: "3.x" python-version: "3.x"
@ -58,7 +59,7 @@ jobs:
uses: aws-actions/setup-sam@v2 uses: aws-actions/setup-sam@v2
- name: Download Layer Artifact - name: Download Layer Artifact
uses: actions/download-artifact@v3 uses: actions/download-artifact@v4
with: with:
name: chromium name: chromium

View File

@ -13,12 +13,12 @@ jobs:
# Install jq so I can edit package.json from the command line # Install jq so I can edit package.json from the command line
- run: sudo apt-get install jq -y - run: sudo apt-get install jq -y
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- name: Setup Node.js - name: Setup Node.js
uses: actions/setup-node@v3 uses: actions/setup-node@v4
with: with:
node-version: 18.x node-version: 20.x
registry-url: https://registry.npmjs.org/ registry-url: https://registry.npmjs.org/
- run: npm ci - run: npm ci
@ -58,7 +58,7 @@ jobs:
cd .. cd ..
- name: Upload items to Github Release - name: Upload items to Github Release
uses: ncipollo/release-action@v1.12.0 uses: ncipollo/release-action@v1.14.0
with: with:
tag: ${{ github.ref_name }} tag: ${{ github.ref_name }}
body: | body: |

1
.gitignore vendored
View File

@ -12,3 +12,4 @@ _/amazon/.aws-sam
*.tgz *.tgz
examples/**/package-lock.json examples/**/package-lock.json
examples/**/.serverless examples/**/.serverless
docker

View File

@ -8,16 +8,19 @@ pretest:
npm install --prefix _/amazon/handlers puppeteer-core@latest --bin-links=false --fund=false --omit=optional --omit=dev --package-lock=false --save=false npm install --prefix _/amazon/handlers puppeteer-core@latest --bin-links=false --fund=false --omit=optional --omit=dev --package-lock=false --save=false
test: test:
sam local invoke --template _/amazon/template.yml --event _/amazon/events/example.com.json node18 sam local invoke --template _/amazon/template.yml --event _/amazon/events/example.com.json node20
.fonts.zip: test16:
zip -9 --filesync --move --recurse-paths .fonts.zip .fonts/ sam local invoke --template _/amazon/template.yml --event _/amazon/events/example.com.json node16
test18:
sam local invoke --template _/amazon/template.yml --event _/amazon/events/example.com.json node18
%.zip: %.zip:
npm install --fund=false --package-lock=false npm install --fund=false --package-lock=false
npm run build npm run build
mkdir -p nodejs mkdir -p nodejs
npm install --prefix nodejs/ tar-fs@2.1.1 follow-redirects@1.15.2 --bin-links=false --fund=false --omit=optional --omit=dev --package-lock=false --save=false npm install --prefix nodejs/ tar-fs@3.0.6 follow-redirects@1.15.9 --bin-links=false --fund=false --omit=optional --omit=dev --package-lock=false --save=false
npm pack npm pack
mkdir -p nodejs/node_modules/@sparticuz/chromium/ mkdir -p nodejs/node_modules/@sparticuz/chromium/
tar --directory nodejs/node_modules/@sparticuz/chromium/ --extract --file sparticuz-chromium-*.tgz --strip-components=1 tar --directory nodejs/node_modules/@sparticuz/chromium/ --extract --file sparticuz-chromium-*.tgz --strip-components=1

View File

@ -50,7 +50,9 @@ const test = require("node:test");
const puppeteer = require("puppeteer-core"); const puppeteer = require("puppeteer-core");
const chromium = require("@sparticuz/chromium"); const chromium = require("@sparticuz/chromium");
// Optional: If you'd like to use the legacy headless mode. "new" is the default. // Optional: If you'd like to use the new headless mode. "shell" is the default.
// NOTE: Because we build the shell binary, this option does not work.
// However, this option will stay so when we migrate to full chromium it will work.
chromium.setHeadlessMode = true; chromium.setHeadlessMode = true;
// Optional: If you'd like to disable webgl, true is the default. // Optional: If you'd like to disable webgl, true is the default.
@ -157,13 +159,13 @@ Here are some example projects and help with other services
- [Serverless Framework with Lambda Layer](https://github.com/Sparticuz/chromium/tree/master/examples/serverless-with-lambda-layer) - [Serverless Framework with Lambda Layer](https://github.com/Sparticuz/chromium/tree/master/examples/serverless-with-lambda-layer)
- [Serverless Framework with Pre-existing Lambda Layer](https://github.com/Sparticuz/chromium/tree/master/examples/serverless-with-preexisting-lambda-layer) - [Serverless Framework with Pre-existing Lambda Layer](https://github.com/Sparticuz/chromium/tree/master/examples/serverless-with-preexisting-lambda-layer)
- [Chromium-min](https://github.com/Sparticuz/chromium/tree/master/examples/remote-min-binary) - [Chromium-min](https://github.com/Sparticuz/chromium/tree/master/examples/remote-min-binary)
- AWS SAM _TODO_ - [AWS SAM](https://github.com/Sparticuz/chromium/tree/master/examples/aws-sam)
- [Webpack](https://github.com/Sparticuz/chromium/issues/24#issuecomment-1343196897) - [Webpack](https://github.com/Sparticuz/chromium/issues/24#issuecomment-1343196897)
- [Netlify](https://github.com/Sparticuz/chromium/issues/24#issuecomment-1414107620) - [Netlify](https://github.com/Sparticuz/chromium/issues/24#issuecomment-1414107620)
### Running Locally & Headless/Headful mode ### Running Locally & Headless/Headful mode
This version of `chromium` is built using the `headless.gn` build variables, which does not appear to even include a GUI. [Also, at this point, AWS Lambda 2 does not support a modern version of `glibc`](https://github.com/aws/aws-lambda-base-images/issues/59), so this package does not include an ARM version yet, which means it will not work on any M Series Apple products. If you need to test your code using a headful or ARM version, please use your locally installed version of `chromium/chrome`, or you may use the `puppeteer` provided version. This version of `chromium` is built using the `headless.gn` build variables, which does not appear to even include a GUI. [Also, at this point, AWS Lambda 2 does not support a modern version of `glibc`](https://github.com/aws/aws-lambda-base-images/issues/59), so this package does not include an ARM version yet, which means it will not work on any M Series Apple products. If you need to test your code using a headful or ARM version, please use your locally installed version of `chromium/chrome`, or you may use the `puppeteer` provided version. Users have reported installing `rosetta` on MacOS will also work.
```shell ```shell
npx @puppeteer/browsers install chromium@latest --path /tmp/localChromium npx @puppeteer/browsers install chromium@latest --path /tmp/localChromium
@ -202,6 +204,50 @@ From what I can tell, `headless_shell` does not seem to include support for the
Try marking this package as an external. Ref: https://webpack.js.org/configuration/externals/ Try marking this package as an external. Ref: https://webpack.js.org/configuration/externals/
### I'm experiencing timeouts or failures closing Chromium
This is a common issue. Chromium sometimes opens up more pages than you ask for. You can try the following
```typescript
for (const page of await browser.pages()) {
await page.close();
}
await browser.close();
```
You can also try the following if one of the calls is hanging for some reason.
```typescript
await Promise.race([browser.close(), browser.close(), browser.close()]);
```
Always `await browser.close()`, even if your script is returning an error.
### I need Accessible pdf files
This is due to the way @sparticuz/chromium is built. If you require accessible pdf's, you'll need to
recompile chromium yourself with the following patch. You can then use that binary with @sparticuz/chromium-min.
_Note_: This will increase the time required to generate a PDF.
```patch
diff --git a/_/ansible/plays/chromium.yml b/_/ansible/plays/chromium.yml
index b42c740..49111d7 100644
--- a/_/ansible/plays/chromium.yml
+++ b/_/ansible/plays/chromium.yml
@@ -249,8 +249,9 @@
blink_symbol_level = 0
dcheck_always_on = false
disable_histogram_support = false
- enable_basic_print_dialog = false
enable_basic_printing = true
+ enable_pdf = true
+ enable_tagged_pdf = true
enable_keystone_registration_framework = false
enable_linux_installer = false
enable_media_remoting = false
```
## Fonts ## Fonts
The Amazon Linux 2 AWS Lambda runtime is not provisioned with any font faces. The Amazon Linux 2 AWS Lambda runtime is not provisioned with any font faces.
@ -232,7 +278,7 @@ This method should be invoked _before_ launching Chromium.
Alternatively, it's also possible to provision fonts via AWS Lambda Layers. Alternatively, it's also possible to provision fonts via AWS Lambda Layers.
Simply create a directory named `.fonts` and place any font faces you want there: Simply create a directory named `.fonts` or `fonts` and place any font faces you want there:
``` ```
.fonts .fonts
@ -243,7 +289,7 @@ Simply create a directory named `.fonts` and place any font faces you want there
Afterwards, you just need to ZIP the directory and upload it as a AWS Lambda Layer: Afterwards, you just need to ZIP the directory and upload it as a AWS Lambda Layer:
```shell ```shell
zip -9 --filesync --move --recurse-paths .fonts.zip .fonts/ zip -9 --filesync --move --recurse-paths fonts.zip fonts/
``` ```
## Graphics ## Graphics
@ -258,8 +304,8 @@ By default, this package uses `swiftshader`/`angle` to do CPU acceleration for W
| `args` | `Array<string>` | Provides a list of recommended additional [Chromium flags](https://github.com/GoogleChrome/chrome-launcher/blob/master/docs/chrome-flags-for-tools.md). | | `args` | `Array<string>` | Provides a list of recommended additional [Chromium flags](https://github.com/GoogleChrome/chrome-launcher/blob/master/docs/chrome-flags-for-tools.md). |
| `defaultViewport` | `Object` | Returns a sensible default viewport for serverless. | | `defaultViewport` | `Object` | Returns a sensible default viewport for serverless. |
| `executablePath(location?: string)` | `Promise<string>` | Returns the path the Chromium binary was extracted to. | | `executablePath(location?: string)` | `Promise<string>` | Returns the path the Chromium binary was extracted to. |
| `setHeadlessMode` | `void` | Sets the headless mode to either `true` or `"new"` | | `setHeadlessMode` | `void` | Sets the headless mode to either `true` or `"shell"` |
| `headless` | `true \| "new"` | Returns `true` or `"new"` depending on what version of chrome's headless you are running | | `headless` | `true \| "shell"` | Returns `true` or `"shell"` depending on what version of chrome's headless you are running |
| `setGraphicsMode` | `void` | Sets the graphics mode to either `true` or `false` | | `setGraphicsMode` | `void` | Sets the graphics mode to either `true` or `false` |
| `graphics` | `boolean` | Returns a boolean depending on whether webgl is enabled or disabled | | `graphics` | `boolean` | Returns a boolean depending on whether webgl is enabled or disabled |

View File

@ -3,21 +3,14 @@
"url": "https://example.com", "url": "https://example.com",
"expected": { "expected": {
"title": "Example Domain", "title": "Example Domain",
"screenshot": "fdd55bf210cb00e00cadf3098055611d11293d02" "screenshot": "e610a8be5568f23c453b08928460aae3ae0b4b0a"
}
},
{
"url": "https://example.com",
"expected": {
"title": "Example Domain",
"screenshot": "fdd55bf210cb00e00cadf3098055611d11293d02"
} }
}, },
{ {
"url": "https://get.webgl.org", "url": "https://get.webgl.org",
"expected": { "expected": {
"remove": "logo-container", "remove": "logo-container",
"screenshot": "7a63a9a18f32dcdad78e1e0a03364fade25c85a8" "screenshot": "ec6c79a571b4cb5727c6fc23f9da30de3868138c"
} }
} }
] ]

View File

@ -1,5 +1,5 @@
const { ok } = require("assert"); const { ok } = require("node:assert");
const { createHash } = require("crypto"); const { createHash } = require("node:crypto");
const puppeteer = require("puppeteer-core"); const puppeteer = require("puppeteer-core");
const chromium = require("@sparticuz/chromium"); const chromium = require("@sparticuz/chromium");
@ -10,22 +10,16 @@ exports.handler = async (event, context) => {
browser = await puppeteer.launch({ browser = await puppeteer.launch({
args: chromium.args, args: chromium.args,
defaultViewport: chromium.defaultViewport, defaultViewport: chromium.defaultViewport,
dumpio: true,
executablePath: await chromium.executablePath(), executablePath: await chromium.executablePath(),
headless: chromium.headless, headless: chromium.headless,
ignoreHTTPSErrors: true, acceptInsecureCerts: true,
}); });
console.log("Chromium verion", await browser.version()); console.log("Chromium version", await browser.version());
const contexts = [browser.defaultBrowserContext()]; for (let job of event) {
const page = await browser.newPage();
while (contexts.length < event.length) {
contexts.push(await browser.createIncognitoBrowserContext());
}
for (let context of contexts) {
const job = event.shift();
const page = await context.newPage();
if (job.hasOwnProperty("url") === true) { if (job.hasOwnProperty("url") === true) {
await page.goto(job.url, { waitUntil: ["domcontentloaded", "load"] }); await page.goto(job.url, { waitUntil: ["domcontentloaded", "load"] });
@ -44,8 +38,15 @@ exports.handler = async (event, context) => {
document.getElementById(selector).remove(); document.getElementById(selector).remove();
}, job.expected.remove); }, job.expected.remove);
} }
const screenshot = await page.screenshot(); const screenshot = Buffer.from(await page.screenshot());
// console.log(screenshot.toString('base64'), createHash('sha1').update(screenshot.toString('base64')).digest('hex')); /*
console.log(
`data:image/png;base64,${screenshot.toString("base64")}`,
createHash("sha1")
.update(screenshot.toString("base64"))
.digest("hex")
);
*/
ok( ok(
createHash("sha1") createHash("sha1")
.update(screenshot.toString("base64")) .update(screenshot.toString("base64"))
@ -60,6 +61,9 @@ exports.handler = async (event, context) => {
throw error.message; throw error.message;
} finally { } finally {
if (browser !== null) { if (browser !== null) {
for (const page of await browser.pages()) {
await page.close();
}
await browser.close(); await browser.close();
} }
} }

View File

@ -14,6 +14,7 @@ Resources:
CompatibleRuntimes: CompatibleRuntimes:
- nodejs16.x - nodejs16.x
- nodejs18.x - nodejs18.x
- nodejs20.x
node16: node16:
Type: AWS::Serverless::Function Type: AWS::Serverless::Function
@ -37,3 +38,14 @@ Resources:
- AWSLambdaBasicExecutionRole - AWSLambdaBasicExecutionRole
- AWSXRayDaemonWriteAccess - AWSXRayDaemonWriteAccess
Tracing: Active Tracing: Active
node20:
Type: AWS::Serverless::Function
Properties:
Layers:
- !Ref layer
Handler: handlers/index.handler
Runtime: nodejs20.x
Policies:
- AWSLambdaBasicExecutionRole
- AWSXRayDaemonWriteAccess
Tracing: Active

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

View File

@ -4,9 +4,9 @@
[localhost:vars] [localhost:vars]
ansible_connection=local ansible_connection=local
ansible_python_interpreter=python ansible_python_interpreter=python
image=ami-08d090f841c8435e9 image=ami-06c68f701d8090592
region=us-east-1 region=us-east-1
instance_size=c6i.12xlarge instance_size=c7i.12xlarge
[aws] [aws]
@ -14,4 +14,4 @@ instance_size=c6i.12xlarge
ansible_connection=ssh ansible_connection=ssh
ansible_python_interpreter=auto_silent ansible_python_interpreter=auto_silent
ansible_ssh_private_key_file=ansible.pem ansible_ssh_private_key_file=ansible.pem
chromium_revision=1192594 chromium_revision=1343869

View File

@ -236,12 +236,6 @@
path: /srv/source/chromium/src/out/Headless path: /srv/source/chromium/src/out/Headless
state: directory state: directory
- name: Mounting Build Directory in Memory
become: true
become_user: root
shell: |
mount --types tmpfs --options size=24G,nr_inodes=128k,mode=1777 tmpfs /srv/source/chromium/src/out/Headless
- name: Creating Headless Chromium Configuration - name: Creating Headless Chromium Configuration
copy: copy:
content: | content: |

BIN
bin/al2.tar.br Normal file

Binary file not shown.

BIN
bin/al2023.tar.br Normal file

Binary file not shown.

Binary file not shown.

BIN
bin/chromium.br Executable file → Normal file

Binary file not shown.

BIN
bin/fonts.tar.br Normal file

Binary file not shown.

Binary file not shown.

1
examples/aws-sam/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.aws-sam

View File

@ -0,0 +1,19 @@
# Chromium as a Layer for AWS SAM
1. Install AWS SAM CLI: https://github.com/aws/aws-sam-cli/
1. Ensure Docker is installed and running: https://www.docker.com/
1. Build the project:
```sh
sam build
```
1. Invoke the AWS Lambda Function locally with:
```sh
sam local invoke ExampleFunction
```
This example connects to https://www.example.com and outputs the page's title as the function result. See the source code in [`app.mjs`](functions/exampleFunction/app.mjs) for more details.

View File

@ -0,0 +1,24 @@
import chromium from '@sparticuz/chromium';
import puppeteer from 'puppeteer-core';
export const lambdaHandler = async (event, context) => {
const browser = await puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath(),
headless: chromium.headless,
});
const page = await browser.newPage();
await page.goto("https://www.example.com", { waitUntil: "networkidle0" });
const browserVersion = await browser.version();
const pageTitle = await page.title();
await page.close();
await browser.close();
return { result: 'success', browserVersion, pageTitle };
}

View File

@ -0,0 +1,13 @@
{
"name": "ExampleFunction",
"private": true,
"version": "0.1.0",
"description": "AWS Lambda Function that loads Chromium. Refer to https://github.com/Sparticuz/chromium#install for compatible versions.",
"main": "app.mjs",
"devDependencies": {
"@sparticuz/chromium": "^119.0.0"
},
"dependencies": {
"puppeteer-core": "^21.5.1"
}
}

View File

@ -0,0 +1,9 @@
{
"name": "ChromiumLayer",
"private": true,
"version": "1.0.0",
"description": "Chromium layer for AWS Lambda",
"dependencies": {
"@sparticuz/chromium": "^119.0.0"
}
}

View File

@ -0,0 +1,33 @@
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: Example configuration for AWS SAM and Chromium
Resources:
ChromiumLayer:
Type: AWS::Serverless::LayerVersion
Properties:
Description: Chromium with Node.js integration for AWS Lambda
ContentUri: layers/chromium
CompatibleRuntimes:
- &nodejsRuntime nodejs18.x
# Chromium doesn't currently have ARM support; see https://github.com/Sparticuz/chromium#can-i-use-arm-or-graviton-instances
CompatibleArchitectures:
- &chromiumArch x86_64
RetentionPolicy: Delete
Metadata:
BuildMethod: *nodejsRuntime
BuildArchitecture: *chromiumArch
ExampleFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: functions/exampleFunction
Handler: app.lambdaHandler
Runtime: *nodejsRuntime
Architectures:
- *chromiumArch
Layers:
- !Ref ChromiumLayer
# Adjust as necessary
Timeout: 30
MemorySize: 1024

137
package-lock.json generated
View File

@ -1,61 +1,65 @@
{ {
"name": "@sparticuz/chromium", "name": "@sparticuz/chromium",
"version": "117.0.0", "version": "130.0.0",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@sparticuz/chromium", "name": "@sparticuz/chromium",
"version": "117.0.0", "version": "130.0.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"follow-redirects": "^1.15.3", "follow-redirects": "^1.15.9",
"tar-fs": "^3.0.4" "tar-fs": "^3.0.6"
}, },
"devDependencies": { "devDependencies": {
"@tsconfig/node16": "^16.1.1", "@tsconfig/node20": "^20.1.4",
"@tsconfig/strictest": "^2.0.2", "@tsconfig/strictest": "^2.0.5",
"@types/follow-redirects": "^1.14.3", "@types/follow-redirects": "^1.14.4",
"@types/node": "^18.18.6", "@types/node": "^20.16.10",
"@types/tar-fs": "^2.0.3", "@types/tar-fs": "^2.0.4",
"clean-modules": "^3.0.4", "clean-modules": "^3.1.1",
"typescript": "^5.2.2" "typescript": "^5.6.2"
}, },
"engines": { "engines": {
"node": ">= 16" "node": ">= 16"
} }
}, },
"node_modules/@tsconfig/node16": { "node_modules/@tsconfig/node20": {
"version": "16.1.1", "version": "20.1.4",
"resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-16.1.1.tgz", "resolved": "https://registry.npmjs.org/@tsconfig/node20/-/node20-20.1.4.tgz",
"integrity": "sha512-+pio93ejHN4nINX4pXqfnR/fPLRtJBaT4ORaa5RH0Oc1zoYmo2B2koG+M328CQhHKn1Wj6FcOxCDFXAot9NhvA==", "integrity": "sha512-sqgsT69YFeLWf5NtJ4Xq/xAF8p4ZQHlmGW74Nu2tD4+g5fAsposc4ZfaaPixVu4y01BEiDCWLRDCvDM5JOsRxg==",
"dev": true "dev": true
}, },
"node_modules/@tsconfig/strictest": { "node_modules/@tsconfig/strictest": {
"version": "2.0.2", "version": "2.0.5",
"resolved": "https://registry.npmjs.org/@tsconfig/strictest/-/strictest-2.0.2.tgz", "resolved": "https://registry.npmjs.org/@tsconfig/strictest/-/strictest-2.0.5.tgz",
"integrity": "sha512-jt4jIsWKvUvuY6adJnQJlb/UR7DdjC8CjHI/OaSQruj2yX9/K6+KOvDt/vD6udqos/FUk5Op66CvYT7TBLYO5Q==", "integrity": "sha512-ec4tjL2Rr0pkZ5hww65c+EEPYwxOi4Ryv+0MtjeaSQRJyq322Q27eOQiFbuNgw2hpL4hB1/W/HBGk3VKS43osg==",
"dev": true "dev": true
}, },
"node_modules/@types/follow-redirects": { "node_modules/@types/follow-redirects": {
"version": "1.14.3", "version": "1.14.4",
"resolved": "https://registry.npmjs.org/@types/follow-redirects/-/follow-redirects-1.14.3.tgz", "resolved": "https://registry.npmjs.org/@types/follow-redirects/-/follow-redirects-1.14.4.tgz",
"integrity": "sha512-VN4w0rKWI4DVySabR5/9P65nwcVEAr1taWFyYW3YR7rHYO/bOgG+LHpWfSzthPmCEfmawuXsMd4huQeSoc7jpg==", "integrity": "sha512-GWXfsD0Jc1RWiFmMuMFCpXMzi9L7oPDVwxUnZdg89kDNnqsRfUKXEtUYtA98A6lig1WXH/CYY/fvPW9HuN5fTA==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@types/node": "*" "@types/node": "*"
} }
}, },
"node_modules/@types/node": { "node_modules/@types/node": {
"version": "18.18.6", "version": "20.16.10",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.18.6.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.16.10.tgz",
"integrity": "sha512-wf3Vz+jCmOQ2HV1YUJuCWdL64adYxumkrxtc+H1VUQlnQI04+5HtH+qZCOE21lBE7gIrt+CwX2Wv8Acrw5Ak6w==", "integrity": "sha512-vQUKgWTjEIRFCvK6CyriPH3MZYiYlNy0fKiEYHWbcoWLEgs4opurGGKlebrTLqdSMIbXImH6XExNiIyNUv3WpA==",
"dev": true "dev": true,
"license": "MIT",
"dependencies": {
"undici-types": "~6.19.2"
}
}, },
"node_modules/@types/tar-fs": { "node_modules/@types/tar-fs": {
"version": "2.0.3", "version": "2.0.4",
"resolved": "https://registry.npmjs.org/@types/tar-fs/-/tar-fs-2.0.3.tgz", "resolved": "https://registry.npmjs.org/@types/tar-fs/-/tar-fs-2.0.4.tgz",
"integrity": "sha512-ADS99HAnztB8MD+LSOdzDrDLcSe5oBIg+SUQwwsgnsOgZobWoSqYmg9ZJWdvLppoKV8R8kZinX6Om+LlsNuIlQ==", "integrity": "sha512-ipPec0CjTmVDWE+QKr9cTmIIoTl7dFG/yARCM5MqK8i6CNLIG1P8x4kwDsOQY1ChZOZjH0wO9nvfgBvWl4R3kA==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@types/node": "*", "@types/node": "*",
@ -76,11 +80,45 @@
"resolved": "https://registry.npmjs.org/b4a/-/b4a-1.6.4.tgz", "resolved": "https://registry.npmjs.org/b4a/-/b4a-1.6.4.tgz",
"integrity": "sha512-fpWrvyVHEKyeEvbKZTVOeZF3VSKKWtJxFIxX/jaVPf+cLbGUSitjb49pHLqPV2BUNNZ0LcoeEGfE/YCpyDYHIw==" "integrity": "sha512-fpWrvyVHEKyeEvbKZTVOeZF3VSKKWtJxFIxX/jaVPf+cLbGUSitjb49pHLqPV2BUNNZ0LcoeEGfE/YCpyDYHIw=="
}, },
"node_modules/bare-events": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/bare-events/-/bare-events-2.2.0.tgz",
"integrity": "sha512-Yyyqff4PIFfSuthCZqLlPISTWHmnQxoPuAvkmgzsJEmG3CesdIv6Xweayl0JkCZJSB2yYIdJyEz97tpxNhgjbg==",
"optional": true
},
"node_modules/bare-fs": {
"version": "2.1.5",
"resolved": "https://registry.npmjs.org/bare-fs/-/bare-fs-2.1.5.tgz",
"integrity": "sha512-5t0nlecX+N2uJqdxe9d18A98cp2u9BETelbjKpiVgQqzzmVNFYWEAjQHqS+2Khgto1vcwhik9cXucaj5ve2WWA==",
"optional": true,
"dependencies": {
"bare-events": "^2.0.0",
"bare-os": "^2.0.0",
"bare-path": "^2.0.0",
"streamx": "^2.13.0"
}
},
"node_modules/bare-os": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/bare-os/-/bare-os-2.2.0.tgz",
"integrity": "sha512-hD0rOPfYWOMpVirTACt4/nK8mC55La12K5fY1ij8HAdfQakD62M+H4o4tpfKzVGLgRDTuk3vjA4GqGXXCeFbag==",
"optional": true
},
"node_modules/bare-path": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/bare-path/-/bare-path-2.1.0.tgz",
"integrity": "sha512-DIIg7ts8bdRKwJRJrUMy/PICEaQZaPGZ26lsSx9MJSwIhSrcdHn7/C8W+XmnG/rKi6BaRcz+JO00CjZteybDtw==",
"optional": true,
"dependencies": {
"bare-os": "^2.1.0"
}
},
"node_modules/clean-modules": { "node_modules/clean-modules": {
"version": "3.0.4", "version": "3.1.1",
"resolved": "https://registry.npmjs.org/clean-modules/-/clean-modules-3.0.4.tgz", "resolved": "https://registry.npmjs.org/clean-modules/-/clean-modules-3.1.1.tgz",
"integrity": "sha512-UtidYdwZScv7TEmPuNBU1IDh2UrLH9FNYnhKYterm3jTtOGtSOa02J5aKHvnauqS/TKqJGPpC4bmuRDAXk61EQ==", "integrity": "sha512-t/7dNtn6vQYxujYxdwZeLa0NsLE92KQ0XeV3CDJ2TXgLTvn3ijmjlQN0Dm9wjYQgC0miZiF66ClTQzgIeYw96A==",
"dev": true, "dev": true,
"license": "ISC",
"dependencies": { "dependencies": {
"clipanion": "^3.2.1", "clipanion": "^3.2.1",
"picomatch": "^2.3.0", "picomatch": "^2.3.0",
@ -121,15 +159,16 @@
"integrity": "sha512-IgfweLvEpwyA4WgiQe9Nx6VV2QkML2NkvZnk1oKnIzXgXdWxuhF7zw4DvLTPZJn6PIUneiAXPF24QmoEqHTjyw==" "integrity": "sha512-IgfweLvEpwyA4WgiQe9Nx6VV2QkML2NkvZnk1oKnIzXgXdWxuhF7zw4DvLTPZJn6PIUneiAXPF24QmoEqHTjyw=="
}, },
"node_modules/follow-redirects": { "node_modules/follow-redirects": {
"version": "1.15.3", "version": "1.15.9",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz",
"integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==", "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==",
"funding": [ "funding": [
{ {
"type": "individual", "type": "individual",
"url": "https://github.com/sponsors/RubenVerborgh" "url": "https://github.com/sponsors/RubenVerborgh"
} }
], ],
"license": "MIT",
"engines": { "engines": {
"node": ">=4.0" "node": ">=4.0"
}, },
@ -139,11 +178,6 @@
} }
} }
}, },
"node_modules/mkdirp-classic": {
"version": "0.5.3",
"resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz",
"integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A=="
},
"node_modules/once": { "node_modules/once": {
"version": "1.4.0", "version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
@ -239,13 +273,16 @@
} }
}, },
"node_modules/tar-fs": { "node_modules/tar-fs": {
"version": "3.0.4", "version": "3.0.6",
"resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-3.0.4.tgz", "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-3.0.6.tgz",
"integrity": "sha512-5AFQU8b9qLfZCX9zp2duONhPmZv0hGYiBPJsyUdqMjzq/mqVpy/rEUSeHk1+YitmxugaptgBh5oDGU3VsAJq4w==", "integrity": "sha512-iokBDQQkUyeXhgPYaZxmczGPhnhXZ0CmrqI+MOb/WFGS9DW5wnfrLgtjUJBvz50vQ3qfRwJ62QVoCFu8mPVu5w==",
"dependencies": { "dependencies": {
"mkdirp-classic": "^0.5.2",
"pump": "^3.0.0", "pump": "^3.0.0",
"tar-stream": "^3.1.5" "tar-stream": "^3.1.5"
},
"optionalDependencies": {
"bare-fs": "^2.1.1",
"bare-path": "^2.1.0"
} }
}, },
"node_modules/tar-stream": { "node_modules/tar-stream": {
@ -265,10 +302,11 @@
"dev": true "dev": true
}, },
"node_modules/typescript": { "node_modules/typescript": {
"version": "5.2.2", "version": "5.6.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.2.tgz",
"integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", "integrity": "sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==",
"dev": true, "dev": true,
"license": "Apache-2.0",
"bin": { "bin": {
"tsc": "bin/tsc", "tsc": "bin/tsc",
"tsserver": "bin/tsserver" "tsserver": "bin/tsserver"
@ -277,6 +315,13 @@
"node": ">=14.17" "node": ">=14.17"
} }
}, },
"node_modules/undici-types": {
"version": "6.19.6",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.6.tgz",
"integrity": "sha512-e/vggGopEfTKSvj4ihnOLTsqhrKRN3LeO6qSN/GxohhuRv8qH9bNQ4B8W7e/vFL+0XTnmHPB4/kegunZGA4Org==",
"dev": true,
"license": "MIT"
},
"node_modules/wrappy": { "node_modules/wrappy": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",

View File

@ -1,6 +1,6 @@
{ {
"name": "@sparticuz/chromium", "name": "@sparticuz/chromium",
"version": "117.0.0", "version": "130.0.0",
"description": "Chromium Binary for Serverless Platforms", "description": "Chromium Binary for Serverless Platforms",
"keywords": [ "keywords": [
"aws", "aws",
@ -36,17 +36,17 @@
"test": "make clean && make && make pretest && make test" "test": "make clean && make && make pretest && make test"
}, },
"dependencies": { "dependencies": {
"follow-redirects": "^1.15.3", "follow-redirects": "^1.15.9",
"tar-fs": "^3.0.4" "tar-fs": "^3.0.6"
}, },
"devDependencies": { "devDependencies": {
"@tsconfig/node16": "^16.1.1", "@tsconfig/node20": "^20.1.4",
"@tsconfig/strictest": "^2.0.2", "@tsconfig/strictest": "^2.0.5",
"@types/follow-redirects": "^1.14.3", "@types/follow-redirects": "^1.14.4",
"@types/node": "^18.18.6", "@types/node": "^20.16.10",
"@types/tar-fs": "^2.0.3", "@types/tar-fs": "^2.0.4",
"clean-modules": "^3.0.4", "clean-modules": "^3.1.1",
"typescript": "^5.2.2" "typescript": "^5.6.2"
}, },
"engines": { "engines": {
"node": ">= 16" "node": ">= 16"

View File

@ -26,12 +26,29 @@ export const isValidUrl = (input: string) => {
export const isRunningInAwsLambda = () => { export const isRunningInAwsLambda = () => {
if ( if (
process.env["AWS_EXECUTION_ENV"] && process.env["AWS_EXECUTION_ENV"] &&
/^AWS_Lambda_nodejs/.test(process.env["AWS_EXECUTION_ENV"]) === true process.env["AWS_EXECUTION_ENV"].includes("AWS_Lambda_nodejs") &&
!process.env["AWS_EXECUTION_ENV"].includes("20.x")
) { ) {
return true; return true;
} else if ( } else if (
process.env["AWS_LAMBDA_JS_RUNTIME"] && process.env["AWS_LAMBDA_JS_RUNTIME"] &&
/^nodejs/.test(process.env["AWS_LAMBDA_JS_RUNTIME"]) === true process.env["AWS_LAMBDA_JS_RUNTIME"].includes("nodejs") &&
!process.env["AWS_LAMBDA_JS_RUNTIME"].includes("20.x")
) {
return true;
}
return false;
};
export const isRunningInAwsLambdaNode20 = () => {
if (
process.env["AWS_EXECUTION_ENV"] &&
process.env["AWS_EXECUTION_ENV"].includes("20.x")
) {
return true;
} else if (
process.env["AWS_LAMBDA_JS_RUNTIME"] &&
process.env["AWS_LAMBDA_JS_RUNTIME"].includes("20.x")
) { ) {
return true; return true;
} }

View File

@ -9,7 +9,12 @@ import { https } from "follow-redirects";
import LambdaFS from "./lambdafs"; import LambdaFS from "./lambdafs";
import { join } from "node:path"; import { join } from "node:path";
import { URL } from "node:url"; import { URL } from "node:url";
import { downloadAndExtract, isRunningInAwsLambda, isValidUrl } from "./helper"; import {
downloadAndExtract,
isRunningInAwsLambda,
isValidUrl,
isRunningInAwsLambdaNode20,
} from "./helper";
/** Viewport taken from https://github.com/puppeteer/puppeteer/blob/main/docs/api/puppeteer.viewport.md */ /** Viewport taken from https://github.com/puppeteer/puppeteer/blob/main/docs/api/puppeteer.viewport.md */
interface Viewport { interface Viewport {
@ -46,17 +51,36 @@ interface Viewport {
if (isRunningInAwsLambda()) { if (isRunningInAwsLambda()) {
if (process.env["FONTCONFIG_PATH"] === undefined) { if (process.env["FONTCONFIG_PATH"] === undefined) {
process.env["FONTCONFIG_PATH"] = "/tmp/aws"; process.env["FONTCONFIG_PATH"] = "/tmp/fonts";
} }
if (process.env["LD_LIBRARY_PATH"] === undefined) { if (process.env["LD_LIBRARY_PATH"] === undefined) {
process.env["LD_LIBRARY_PATH"] = "/tmp/aws/lib"; process.env["LD_LIBRARY_PATH"] = "/tmp/al2/lib";
} else if ( } else if (
process.env["LD_LIBRARY_PATH"].startsWith("/tmp/aws/lib") !== true process.env["LD_LIBRARY_PATH"].startsWith("/tmp/al2/lib") !== true
) { ) {
process.env["LD_LIBRARY_PATH"] = [ process.env["LD_LIBRARY_PATH"] = [
...new Set([ ...new Set([
"/tmp/aws/lib", "/tmp/al2/lib",
...process.env["LD_LIBRARY_PATH"].split(":"),
]),
].join(":");
}
}
if (isRunningInAwsLambdaNode20()) {
if (process.env["FONTCONFIG_PATH"] === undefined) {
process.env["FONTCONFIG_PATH"] = "/tmp/fonts";
}
if (process.env["LD_LIBRARY_PATH"] === undefined) {
process.env["LD_LIBRARY_PATH"] = "/tmp/al2023/lib";
} else if (
process.env["LD_LIBRARY_PATH"].startsWith("/tmp/al2023/lib") !== true
) {
process.env["LD_LIBRARY_PATH"] = [
...new Set([
"/tmp/al2023/lib",
...process.env["LD_LIBRARY_PATH"].split(":"), ...process.env["LD_LIBRARY_PATH"].split(":"),
]), ]),
].join(":"); ].join(":");
@ -69,7 +93,7 @@ class Chromium {
* https://developer.chrome.com/articles/new-headless/#try-out-the-new-headless * https://developer.chrome.com/articles/new-headless/#try-out-the-new-headless
* @values true or "new" * @values true or "new"
*/ */
private static headlessMode: true | "new" = "new"; private static headlessMode: true | "shell" = "shell";
/** /**
* If true, the graphics stack and webgl is enabled, * If true, the graphics stack and webgl is enabled,
@ -199,6 +223,7 @@ class Chromium {
"--no-default-browser-check", // https://source.chromium.org/search?q=lang:cpp+symbol:kNoDefaultBrowserCheck&ss=chromium "--no-default-browser-check", // https://source.chromium.org/search?q=lang:cpp+symbol:kNoDefaultBrowserCheck&ss=chromium
"--no-pings", // https://source.chromium.org/search?q=lang:cpp+symbol:kNoPings&ss=chromium "--no-pings", // https://source.chromium.org/search?q=lang:cpp+symbol:kNoPings&ss=chromium
"--single-process", // Needs to be single-process to avoid `prctl(PR_SET_NO_NEW_PRIVS) failed` error "--single-process", // Needs to be single-process to avoid `prctl(PR_SET_NO_NEW_PRIVS) failed` error
"--font-render-hinting=none", // https://github.com/puppeteer/puppeteer/issues/2410#issuecomment-560573612
]; ];
const chromiumDisableFeatures = [ const chromiumDisableFeatures = [
"AudioServiceOutOfProcess", "AudioServiceOutOfProcess",
@ -215,9 +240,11 @@ class Chromium {
]; ];
// https://chromium.googlesource.com/chromium/src/+/main/docs/gpu/swiftshader.md // https://chromium.googlesource.com/chromium/src/+/main/docs/gpu/swiftshader.md
this.graphics // Blocked by https://github.com/Sparticuz/chromium/issues/247
? graphicsFlags.push("--use-gl=angle", "--use-angle=swiftshader") //this.graphics
: graphicsFlags.push("--disable-webgl"); // ? graphicsFlags.push("--use-gl=angle", "--use-angle=swiftshader")
// : graphicsFlags.push("--disable-webgl");
graphicsFlags.push("--use-gl=angle", "--use-angle=swiftshader");
const insecureFlags = [ const insecureFlags = [
"--allow-running-insecure-content", // https://source.chromium.org/search?q=lang:cpp+symbol:kAllowRunningInsecureContent&ss=chromium "--allow-running-insecure-content", // https://source.chromium.org/search?q=lang:cpp+symbol:kAllowRunningInsecureContent&ss=chromium
@ -229,7 +256,7 @@ class Chromium {
]; ];
const headlessFlags = [ const headlessFlags = [
this.headless === "new" ? "--headless='new'" : "--headless", this.headless === "shell" ? "--headless='shell'" : "--headless",
]; ];
return [ return [
@ -300,14 +327,20 @@ class Chromium {
} }
// Extract the required files // Extract the required files
const promises = [LambdaFS.inflate(`${input}/chromium.br`)]; const promises = [
LambdaFS.inflate(`${input}/chromium.br`),
LambdaFS.inflate(`${input}/fonts.tar.br`),
];
if (this.graphics) { if (this.graphics) {
// Only inflate graphics stack if needed // Only inflate graphics stack if needed
promises.push(LambdaFS.inflate(`${input}/swiftshader.tar.br`)); promises.push(LambdaFS.inflate(`${input}/swiftshader.tar.br`));
} }
if (isRunningInAwsLambda()) { if (isRunningInAwsLambda()) {
// If running in AWS Lambda, extract more required files // If running in AWS Lambda, extract more required files
promises.push(LambdaFS.inflate(`${input}/aws.tar.br`)); promises.push(LambdaFS.inflate(`${input}/al2.tar.br`));
}
if (isRunningInAwsLambdaNode20()) {
promises.push(LambdaFS.inflate(`${input}/al2023.tar.br`));
} }
// Await all extractions // Await all extractions
@ -318,10 +351,10 @@ class Chromium {
/** /**
* Returns the headless mode. * Returns the headless mode.
* `true` means the 'old' (legacy, chromium < 112) headless mode. * "shell" means the 'old' (legacy, chromium < 112) headless mode.
* "new" means the 'new' headless mode. * `true` means the 'new' headless mode.
* https://developer.chrome.com/articles/new-headless/#try-out-the-new-headless * https://developer.chrome.com/articles/new-headless/#try-out-the-new-headless
* @returns true | "new" * @returns true | "shell"
*/ */
public static get headless() { public static get headless() {
return this.headlessMode; return this.headlessMode;
@ -329,18 +362,18 @@ class Chromium {
/** /**
* Sets the headless mode. * Sets the headless mode.
* `true` means the 'old' (legacy, chromium < 112) headless mode. * "shell" means the 'old' (legacy, chromium < 112) headless mode.
* "new" means the 'new' headless mode. * `true` means the 'new' headless mode.
* https://developer.chrome.com/articles/new-headless/#try-out-the-new-headless * https://developer.chrome.com/articles/new-headless/#try-out-the-new-headless
* @default "new" * @default "shell"
*/ */
public static set setHeadlessMode(value: true | "new") { public static set setHeadlessMode(value: true | "shell") {
if ( if (
(typeof value === "string" && value !== "new") || (typeof value === "string" && value !== "shell") ||
(typeof value === "boolean" && value !== true) (typeof value === "boolean" && value !== true)
) { ) {
throw new Error( throw new Error(
`Headless mode must be either \`true\` or 'new', you entered '${value}'` `Headless mode must be either \`true\` or 'shell', you entered '${value}'`
); );
} }
this.headlessMode = value; this.headlessMode = value;
@ -367,7 +400,11 @@ class Chromium {
`Graphics mode must be a boolean, you entered '${value}'` `Graphics mode must be a boolean, you entered '${value}'`
); );
} }
this.graphicsMode = value;
// Disabling 'disabling the gpu'
// Blocked by https://github.com/Sparticuz/chromium/issues/247
// this.graphicsMode = value;
this.graphicsMode = true;
} }
} }

View File

@ -72,4 +72,4 @@ class LambdaFS {
} }
} }
export = LambdaFS; export default LambdaFS;

View File

@ -1,10 +1,10 @@
{ {
"extends": ["@tsconfig/node16/tsconfig", "@tsconfig/strictest"], "extends": ["@tsconfig/node20/tsconfig", "@tsconfig/strictest"],
"compilerOptions": { "compilerOptions": {
"declaration": true, "declaration": true,
"lib": ["dom", "ES2021"], "lib": ["dom", "ES2023"],
"module": "Node16", "module": "NodeNext",
"moduleResolution": "Node16", "moduleResolution": "NodeNext",
"outDir": "build" "outDir": "build"
}, },
"include": ["source"] "include": ["source"]