Compare commits

..

240 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
Sparticuz cf7443fedc update tsconfig 2023-10-23 12:26:58 -04:00
Sparticuz 0e04dd710c update permissions 2023-10-23 12:10:30 -04:00
Sparticuz 8b63fb075d update deps 2023-10-23 12:08:55 -04:00
Kyle McNally 6d190e5ebb Chromium 118 2023-10-20 16:46:27 -04:00
Sparticuz 29c2468ccf 117.0.0 2023-09-19 13:32:31 -04:00
Kyle McNally 506d4c2cd7
Merge pull request #161 from Sparticuz/chromium/117 2023-09-19 13:29:08 -04:00
Sparticuz a6e6e8dfad fix permissions 2023-09-19 13:23:16 -04:00
Kyle McNally 5042a820c1 Chromium 117 2023-09-19 13:21:36 -04:00
Kyle McNally 161d9efbf5 add FAQ 2023-09-19 13:18:23 -04:00
Kyle McNally 67e1c394a5 Update build instance 2023-09-19 13:17:56 -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
Kyle McNally 93954a5217
Merge pull request #149 from Jamesllllllllll/master 2023-09-01 13:09:40 -04:00
James 60971353a8 Correct a few typos 2023-08-29 22:38:56 -04: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
Sparticuz a3999e7b35 116.0.0 2023-08-18 17:27:33 -04:00
Kyle McNally 27ba2eeaf9
Merge pull request #139 from Sparticuz/feature/116 2023-08-18 17:25:53 -04:00
Kyle McNally 11d63b6be6 Chromium 116 2023-08-18 17:21:30 -04:00
Kyle McNally 9626bb09d9 update deps 2023-08-18 17:17:35 -04:00
Kyle McNally 6fc18b6935 lint 2023-08-18 17:13:45 -04:00
Sparticuz aeee592507 115.0.0 2023-07-24 15:11:55 -04:00
Kyle McNally 9f0ae64364
Merge pull request #128 from Sparticuz/feature/chromium115 2023-07-24 14:56:44 -04:00
Kyle McNally 2f57d09fe6 Chromium 115 2023-07-21 17:16:07 -04:00
Sparticuz 74283507ac 114.0.0 2023-06-12 13:55:15 -04:00
Kyle McNally 657597064f
Merge pull request #111 from Sparticuz/feature/chromium114 2023-06-12 13:52:50 -04:00
Sparticuz 07b12068f8 Chromium 114 2023-06-12 13:38:08 -04:00
Sparticuz b8a406a793 113.0.1 2023-05-05 14:40:35 -04:00
Kyle McNally b21fdacfc3
Merge pull request #98 from Sparticuz/fix/netlify 2023-05-05 14:39:47 -04:00
Sparticuz 3b51330eeb Update deps 2023-05-05 14:36:19 -04:00
Sparticuz 7c333430bd add netlify env check 2023-05-05 14:34:10 -04:00
Sparticuz b1810b4165 113.0.0 2023-05-04 12:43:17 -04:00
Kyle McNally 2c2eebac1f
Merge pull request #97 from Sparticuz/feature/chromium113 2023-05-04 12:41:38 -04:00
Kyle McNally ccf85f2fdb
Merge branch 'master' into feature/chromium113 2023-05-04 12:20:32 -04:00
Sparticuz c72041fcd0 change file permissions 2023-05-04 10:06:16 -04:00
Sparticuz 71b254abe4 remove node 14 2023-05-03 16:36:08 -04:00
Sparticuz 0786301a85 Drop node 14 support 2023-05-03 16:30:08 -04:00
Sparticuz ffc8ec4c1d Update to chromium 113 2023-05-03 16:09:17 -04:00
Kyle McNally 96f0556ba3
Merge pull request #86 from Sparticuz/dependabot/npm_and_yarn/typescript-5.0.4 2023-04-12 15:02:07 -04:00
dependabot[bot] 1b7fc2fae9
Bump typescript from 5.0.3 to 5.0.4
Bumps [typescript](https://github.com/Microsoft/TypeScript) from 5.0.3 to 5.0.4.
- [Release notes](https://github.com/Microsoft/TypeScript/releases)
- [Commits](https://github.com/Microsoft/TypeScript/compare/v5.0.3...v5.0.4)

---
updated-dependencies:
- dependency-name: typescript
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-10 10:11:51 +00:00
Kyle McNally 5cbee63a08
Merge pull request #83 from Sparticuz/dependabot/npm_and_yarn/typescript-5.0.3 2023-04-04 14:51:28 -04:00
Kyle McNally 773a268a66
Merge pull request #84 from Sparticuz/dependabot/npm_and_yarn/types/node-18.15.11 2023-04-04 14:51:12 -04:00
dependabot[bot] 2182f18937
Bump @types/node from 18.15.7 to 18.15.11
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 18.15.7 to 18.15.11.
- [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-04-03 10:04:30 +00:00
dependabot[bot] 98938c1ff4
Bump typescript from 5.0.2 to 5.0.3
Bumps [typescript](https://github.com/Microsoft/TypeScript) from 5.0.2 to 5.0.3.
- [Release notes](https://github.com/Microsoft/TypeScript/releases)
- [Commits](https://github.com/Microsoft/TypeScript/commits)

---
updated-dependencies:
- dependency-name: typescript
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-03 10:04:16 +00:00
Sparticuz 9d49cf74d9 112.0.2 2023-03-29 14:22:29 -04:00
Kyle McNally 4c7f43d497
Merge pull request #81 from Sparticuz/fix/single-process 2023-03-29 14:22:12 -04:00
Sparticuz 6b87b60d1a Re-add to avoid chromium error 2023-03-29 14:08:46 -04:00
Sparticuz dfdd205528 112.0.1 2023-03-27 13:29:23 -04:00
Kyle McNally 852a34f88b
Merge pull request #76 from Sparticuz/refactor-args 2023-03-27 13:13:44 -04:00
Sparticuz 8ab732f14e more cleanup 2023-03-27 12:46:23 -04:00
Sparticuz f337cdad26 Added complete example 2023-03-27 12:29:52 -04:00
Sparticuz 503db13867 Add pre-existing lambda layer example
fixes #77
2023-03-27 12:25:01 -04:00
Sparticuz a7320dd0e2 Add docs on how to run locally and headfully
fixes #63
fixes #69
fixes #38
fixes #55
fixes #42
fixes #28
2023-03-27 11:50:24 -04:00
Sparticuz 325fcdc21f Move api docs and add headless and graphics api 2023-03-27 11:42:06 -04:00
Sparticuz a5905cc5bc Add graphics docs 2023-03-27 11:41:33 -04:00
Sparticuz d4d290ac54 Update README.md 2023-03-27 11:40:34 -04:00
Sparticuz 665283328a Cleanup docs 2023-03-27 11:40:18 -04:00
Sparticuz 47dc5aef53 Verify the value of setHeadlessMode 2023-03-27 09:41:12 -04:00
Sparticuz 3f6eb9ee91 Refactor graphics mode 2023-03-27 09:40:51 -04:00
Sparticuz 0c1351f01b Refactor headless mode
now uses getter and setter
2023-03-27 09:24:08 -04:00
Sparticuz b57702b414 Make sure the awslambda check only returns a boolean 2023-03-27 09:21:44 -04:00
Sparticuz 38e10469c5 Pull out the aws lambda check into it's own function 2023-03-27 08:46:00 -04:00
Sparticuz e0a6b12631 refactor args 2023-03-24 15:50:13 -04:00
Sparticuz e5bd99a1f9 Add headless type and graphics stack type 2023-03-24 15:49:51 -04:00
Sparticuz 1889639200 breaking: Move font download to use follow-redirects
deprecates http font downloads
2023-03-24 15:43:50 -04:00
Sparticuz 456b5d58e3 Remove node version check
fixes #75
2023-03-24 15:42:36 -04:00
Sparticuz 6eb3149980 112.0.0 2023-03-24 09:48:19 -04:00
Kyle McNally 3b2668d465
Merge pull request #74 from Sparticuz/chromium112 2023-03-24 09:42:33 -04:00
Sparticuz 0d77a3c6ed Update to chromium 112 2023-03-24 09:37:27 -04:00
Sparticuz f26740b0ea more prettier 2023-03-24 09:35:44 -04:00
Sparticuz 3ab680c5e4 update node types 2023-03-24 09:29:59 -04:00
Sparticuz 30933b91b1 Prettier 2023-03-24 09:29:34 -04:00
Kyle McNally fe8e52d89d
Merge pull request #71 from Sparticuz/dependabot/npm_and_yarn/types/node-18.15.3 2023-03-24 09:11:29 -04:00
Kyle McNally 6352e67925
Merge pull request #72 from Sparticuz/dependabot/npm_and_yarn/typescript-5.0.2 2023-03-24 09:11:04 -04:00
dependabot[bot] e147b8ea40
Bump typescript from 4.9.5 to 5.0.2
Bumps [typescript](https://github.com/Microsoft/TypeScript) from 4.9.5 to 5.0.2.
- [Release notes](https://github.com/Microsoft/TypeScript/releases)
- [Commits](https://github.com/Microsoft/TypeScript/compare/v4.9.5...v5.0.2)

---
updated-dependencies:
- dependency-name: typescript
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-20 10:07:56 +00:00
dependabot[bot] 0335251da0
Bump @types/node from 18.14.0 to 18.15.3
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 18.14.0 to 18.15.3.
- [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-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-20 10:07:40 +00:00
Sparticuz efecce8736 111.0.0 2023-02-20 13:43:35 -05:00
Sparticuz 6e12eeb52e Generate release notes 2023-02-20 13:40:46 -05:00
Kyle McNally 47fcf6ccfc
Merge pull request #47 from Sparticuz/dependabot/npm_and_yarn/typescript-4.9.5 2023-02-20 13:32:12 -05:00
Kyle McNally f82321a695
Merge pull request #62 from Sparticuz/dependabot/npm_and_yarn/types/node-18.14.0 2023-02-20 13:31:58 -05:00
Kyle McNally 1631926197
Merge pull request #61 from Sparticuz/feature/111 2023-02-20 13:28:08 -05:00
Sparticuz 2192fedc04 hash change
I couldn't tell any differences between chromium 110 and 111, so I'm not sure what changed
2023-02-20 13:24:59 -05:00
dependabot[bot] 48f29e0403
Bump @types/node from 18.11.18 to 18.14.0
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 18.11.18 to 18.14.0.
- [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-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-20 10:14:25 +00:00
Sparticuz d9ab0d2058 Add Chromium 111 2023-02-13 15:35:07 -05:00
Kyle McNally 3aca06d426
Delete .gitkeep 2023-02-10 14:42:47 -05:00
Kyle McNally 9e148b56f3
Merge pull request #59 from Sparticuz/feature/examples 2023-02-10 14:40:42 -05:00
Sparticuz 8c2a664099 Update README.md 2023-02-10 14:37:50 -05:00
Sparticuz 0b03ea9de2 lint 2023-02-10 14:31:43 -05:00
Sparticuz 0f1d01e4c8 Add chromium-min example 2023-02-10 14:24:07 -05:00
Sparticuz d8acc9c8d5 110.0.1 2023-02-10 14:04:37 -05:00
Kyle McNally b077bd9340
Merge pull request #57 from Sparticuz/fix/followRedirects 2023-02-10 14:03:17 -05:00
Sparticuz 509470c5cb Also add follow-redirects to the lambda layer 2023-02-10 13:53:52 -05:00
Sparticuz 48b9273bfb Add follow-redirects
Will probably switch to node-fetch when this project goes to ESM
2023-02-10 07:20:11 -05:00
dependabot[bot] 16b3817e52
Bump typescript from 4.9.4 to 4.9.5
Bumps [typescript](https://github.com/Microsoft/TypeScript) from 4.9.4 to 4.9.5.
- [Release notes](https://github.com/Microsoft/TypeScript/releases)
- [Commits](https://github.com/Microsoft/TypeScript/compare/v4.9.4...v4.9.5)

---
updated-dependencies:
- dependency-name: typescript
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-09 17:06:31 +00:00
Sparticuz fcfc6b72d8 sort package.json 2023-02-09 11:51:27 -05:00
Kyle McNally 58460d821c
Merge pull request #54 from Sparticuz/feature/examples 2023-02-09 11:26:27 -05:00
Sparticuz 3737536c95 Add a few todo examples 2023-02-09 11:23:24 -05:00
Sparticuz dcec05abfc Add serverless-with-lambda-layer example 2023-02-09 10:47:19 -05:00
Sparticuz b8bfaffda1 Add production-dependency example 2023-02-09 10:21:16 -05:00
Sparticuz dc0a61daa1 lint 2023-02-09 09:23:01 -05:00
Kyle McNally f9d6faebe1
Merge pull request #52 from Sparticuz/fix/49 2023-02-09 09:16:37 -05:00
Sparticuz ba2b8b694f Build the typescript when building the layer manually 2023-02-09 08:51:28 -05:00
Sparticuz c7284f47ea 110.0.0 2023-01-24 12:24:48 -05:00
Kyle McNally 58bf66e575
Merge pull request #44 from Sparticuz/chromium/110 2023-01-24 12:21:03 -05:00
Sparticuz 29ee254e56 Update to Chromium 110.0.5478.0 2023-01-24 12:15:36 -05:00
Sparticuz bb9b97fb74 remove `use_brlapi` in build
WARNING at build arg file (use "gn args <out_dir>" to edit):18:14: Build argument has no effect.
use_brlapi = 0
             ^
Did you mean "use_vaapi"?

The variable "use_brlapi" was set as a build argument
but never appeared in a declare_args() block in any buildfile.

To view all possible args, run "gn args --list <out_dir>"

The build continued as if that argument was unspecified.

Done. Made 18000 targets from 3088 files in 3657ms
2023-01-24 11:58:50 -05:00
Sparticuz 5424a18a82 args: warn: deprecated in ansible 2.14 2023-01-24 10:40:15 -05:00
Sparticuz ee4c497e64 Update amazon ami to latest AL2022 2023-01-24 09:24:22 -05:00
Sparticuz a4d7b52dce Fix build warning
WARNING at build arg file (use "gn args <out_dir>" to edit):10:27: Build argument has no effect.
enable_one_click_signin = false
                          ^----
The variable "enable_one_click_signin" was set as a build argument
but never appeared in a declare_args() block in any buildfile.

To view all possible args, run "gn args --list <out_dir>"

The build continued as if that argument was unspecified.

Done. Made 18000 targets from 3088 files in 3670ms
2023-01-24 09:23:52 -05:00
Sparticuz 0270285a4a Add more -min documentation 2023-01-13 16:04:06 -05:00
Sparticuz 12764483af Add release body text 2023-01-13 15:44:30 -05:00
Sparticuz 4f4a2159ea 109.0.6 2023-01-13 15:30:23 -05:00
Sparticuz 94f9f9b59a Need to create the layer before creating -min 2023-01-13 15:30:17 -05:00
Sparticuz 52a16b8d7d 109.0.5 2023-01-13 15:26:52 -05:00
Sparticuz 7bd39feec3 Try adding the registry 2023-01-13 15:26:39 -05:00
Sparticuz c42af097d4 109.0.4 2023-01-13 15:20:10 -05:00
Sparticuz 639b156f72 add node_auth_token to publish 2023-01-13 15:19:55 -05:00
Sparticuz 40428cc139 109.0.3 2023-01-13 15:07:31 -05:00
Kyle McNally 640fcc3be1
Merge pull request #37 from Sparticuz/dependabot/github_actions/actions/setup-python-4 2023-01-13 15:04:45 -05:00
Sparticuz 65afc2c0c9 109.0.2 2023-01-13 15:02:10 -05:00
Sparticuz f4e3518619 Fix release action 2023-01-13 14:59:55 -05:00
Sparticuz 4fb4a6f17d Update readme 2023-01-13 14:55:41 -05:00
dependabot[bot] 10d3f8b9eb
Bump actions/setup-python from 3 to 4
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 3 to 4.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v3...v4)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-13 19:38:17 +00:00
Kyle McNally 71d4abf4a3
Merge pull request #36 from Sparticuz/feature/min 2023-01-13 14:37:53 -05:00
Sparticuz 1a1d068697 cleanup 2023-01-13 14:31:22 -05:00
Sparticuz 0a26693b5f update testing workflow 2023-01-13 14:01:41 -05:00
Sparticuz 24ff717fe7 add release, clarify package type 2023-01-13 13:57:45 -05:00
Sparticuz 4d8feb364d Remove npm scripts 2023-01-13 13:55:29 -05:00
Sparticuz 62bc5aea17 convert to @tsconfig node 14 base 2023-01-13 13:51:55 -05:00
Sparticuz e79d99d8ff add dependabot 2023-01-13 13:48:50 -05:00
Sparticuz 1c72dc036c Cleanup .gitignore 2023-01-13 13:47:58 -05:00
Sparticuz 083fd747ff Fix downloadAndExtract to resolve on finish 2023-01-13 10:16:37 -05:00
Vu Nguyen 9e34256b2f chore: resolve comment 2023-01-11 09:35:18 +07:00
Vu Nguyen 3deea91193 feat: load chromium binary remote 2023-01-06 04:06:32 +00:00
Kyle McNally b286dc3fc2
Merge pull request #30 from Sparticuz/fix/cleanup 2022-12-30 11:39:57 -05:00
Sparticuz 03ec742402 font should return a promise with null here, instead of just null 2022-12-30 11:28:52 -05:00
Sparticuz 9578aa0154 Cleanup typescript and lint 2022-12-30 11:28:32 -05:00
Sparticuz 1ef67ceae8 Cleanup old node versions 2022-12-30 11:27:52 -05:00
Sparticuz 0bc1e5d1ba 109.0.1 2022-12-28 14:06:20 -05:00
Sparticuz 60245f16bf Cleanup Readme 2022-12-28 10:32:56 -05:00
Sparticuz 0562aca09f Refactor executablePath a little bit
Thanks @aquarius6666 for the initial code!
2022-12-28 10:27:37 -05:00
Kyle McNally 4cda3ab393
Merge pull request #26 from aqaurius6666/master
Partially fixes #18
2022-12-28 09:11:39 -05:00
Vu Nguyen db8a2f8187 chore: update readme 2022-12-15 14:07:52 +07:00
Vu Nguyen 5d81cf2367 feat: add alternative location for executablePath 2022-12-15 13:50:48 +07:00
50 changed files with 1556 additions and 372 deletions

2
.github/FUNDING.yml vendored
View File

@ -1 +1 @@
github:Sparticuz
github: Sparticuz

View File

@ -12,10 +12,11 @@ For Playwright-specific bugs, please refer to: https://github.com/microsoft/play
-->
## Environment
* `chromium` Version:
* `puppeteer` / `puppeteer-core` Version:
* Node.js Version: <!-- 14.x | 16.x -->
* Lambda / GCF Runtime: <!-- `nodejs8.10` | `nodejs10.x` | `nodejs12.x` -->
- `chromium` Version:
- `puppeteer` / `puppeteer-core` Version:
- Node.js Version: <!-- 16.x | 18.x -->
- Lambda / GCF Runtime: <!-- `nodejs16` | `nodejs18.x` -->
## Expected Behavior
@ -41,7 +42,7 @@ exports.handler = async (event, context, callback) => {
browser = await puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath,
executablePath: await chromium.executablePath(),
headless: chromium.headless,
ignoreHTTPSErrors: true,
});

10
.github/dependabot.yml vendored Normal file
View File

@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: /
schedule:
interval: "weekly"
- package-ecosystem: "github-actions"
directory: /
schedule:
interval: "weekly"

View File

@ -2,9 +2,9 @@ name: AWS Lambda CI
on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]
jobs:
build:
@ -12,21 +12,24 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18.x
node-version: 20.x
- name: Install Packages
run: npm install
run: npm ci
- name: Compile Typescript
run: npm run build
- name: Create Lambda Layer
run: make chromium.zip
- name: Upload Layer Artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: chromium
path: chromium.zip
@ -40,23 +43,23 @@ jobs:
event:
- example.com
version:
- 14
- 16
- 18
- 20
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: '3.x'
python-version: "3.x"
- name: Setup AWS SAM CLI
uses: aws-actions/setup-sam@v2
- name: Download Layer Artifact
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: chromium

79
.github/workflows/release.yml vendored Normal file
View File

@ -0,0 +1,79 @@
name: Release
on:
push:
tags:
- "*"
jobs:
release:
name: Build and release
runs-on: ubuntu-latest
steps:
# Install jq so I can edit package.json from the command line
- run: sudo apt-get install jq -y
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm run build
- name: Release chromium on npmjs
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
- name: Create Lambda Layer
run: make chromium-${{ github.ref_name }}-layer.zip
# Change the package name to chromium-min,
# delete the bin folder from the files array
# so that it doesn't publish the binaries to -min
- name: Cleanup and prepare for chromium-min
run: |
jq '.name="@sparticuz/chromium-min"' package.json > .package.json
jq 'del(.files[] | select(. == "bin"))' .package.json > package.json
jq '.homepage="https://github.com/Sparticuz/chromium#-min-package"' package.json > .package.json
mv .package.json package.json
rm package-lock.json
npm install
- name: Release chromium-min on npmjs
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
- name: Create Chromium Pack
run: |
cd bin
tar -cvf chromium-${{ github.ref_name }}-pack.tar *
mv chromium-${{ github.ref_name }}-pack.tar ..
cd ..
- name: Upload items to Github Release
uses: ncipollo/release-action@v1.14.0
with:
tag: ${{ github.ref_name }}
body: |
# [@sparticuz/chromium ${{ github.ref_name }}](https://www.npmjs.com/package/@sparticuz/chromium), [@sparticuz/chromium-min ${{ github.ref_name }}](https://www.npmjs.com/package/@sparticuz/chromium-min)
The `chromium-${{ github.ref_name }}-layer.zip` file may be uploaded directly as a layer in AWS Lambda using the following code
```
bucketName="chromiumUploadBucket" && \
aws s3 cp chromium-${{ github.ref_name }}-layer.zip "s3://${bucketName}/chromiumLayers/chromium-${{ github.ref_name }}-layer.zip" && \
aws lambda publish-layer-version --layer-name chromium --description "Chromium ${{ github.ref_name }}" --content "S3Bucket=${bucketName},S3Key=chromiumLayers/chromium-${{ github.ref_name }}-layer.zip" --compatible-runtimes nodejs --compatible-architectures x86_64
```
The `chromium-${{ github.ref_name }}-pack.tar` file may be uploaded to any https endpoint and the remote location may be used as the `input` variable in the `chromium.executablePath(input)` function.
artifacts: "chromium-${{ github.ref_name }}-layer.zip,chromium-${{ github.ref_name }}-pack.tar"
prerelease: false
draft: true
generateReleaseNotes: true
token: ${{ github.token }}
owner: Sparticuz
repo: chromium

7
.gitignore vendored
View File

@ -1,5 +1,4 @@
.fonts
*.log
*.pem
*.pem.pub
*.zip
@ -7,6 +6,10 @@ bin/chromium-*.br
build
node_modules
nodejs
package-lock.json
_/amazon/samconfig.toml
_/amazon/.aws-sam
*.tar
*.tgz
examples/**/package-lock.json
examples/**/.serverless
docker

View File

@ -1,3 +0,0 @@
_
.fonts
*.zip

View File

@ -8,19 +8,23 @@ pretest:
npm install --prefix _/amazon/handlers puppeteer-core@latest --bin-links=false --fund=false --omit=optional --omit=dev --package-lock=false --save=false
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:
zip -9 --filesync --move --recurse-paths .fonts.zip .fonts/
test16:
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:
npm install --fund=false --package-lock=false
npm run build
mkdir -p nodejs
npm install --prefix nodejs/ tar-fs@2.1.1 --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
mkdir -p nodejs/node_modules/@sparticuz/chromium/
tar --directory nodejs/node_modules/@sparticuz/chromium/ --extract --file sparticuz-chromium-*.tgz --strip-components=1
npx clean-modules --directory nodejs --include "**/*.d.ts" "**/@types/**" "**/*.@(yaml|yml)" --yes
npx clean-modules --directory nodejs "**/*.d.ts" "**/@types/**" "**/*.@(yaml|yml)" --yes
rm sparticuz-chromium-*.tgz
mkdir -p $(dir $@)
zip -9 --filesync --move --recurse-paths $@ nodejs

249
README.md
View File

@ -1,34 +1,37 @@
# @sparticuz/chromium
[![@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/)
[![Chromium](https://img.shields.io/github/size/sparticuz/chromium/bin/chromium.br?label=Chromium&style=for-the-badge)](bin/)
[![npm](https://img.shields.io/npm/dw/@sparticuz/chromium?label=%40sparticuz%2Fchromium&style=for-the-badge)](https://www.npmjs.com/package/@sparticuz/chromium)
[![npm](https://img.shields.io/npm/dw/@sparticuz/chromium-min?label=%40sparticuz%2Fchromium-min&style=for-the-badge)](https://www.npmjs.com/package/@sparticuz/chromium-min)
[![Donate](https://img.shields.io/badge/donate-paypal-orange.svg?style=for-the-badge)](https://paypal.me/sparticuz)
## Chromium for Serverless platforms
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.
[sparticuz/chrome-aws-lambda](https://github.com/sparticuz/chrome-aws-lambda) 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, but also does not include the overrides and hooks that the original package contained. It is only `chromium`, as well as the special code needed to decompress the brotli package.
However, it quickly became difficult to maintain because of the pace of `puppeteer` updates. This package, `@sparticuz/chromium`, is not chained to `puppeteer` versions, but also does not include the overrides and hooks that the original package contained. It is only `chromium`, as well as the special code needed to decompress the brotli package, and a set of predefined arguments tailored to serverless usage.
## Install
[`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).
[`puppeteer` ships with a preferred 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).
> 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
# Puppeteer or Playwright is a production dependency
npm install --save puppeteer-core@$PUPPETEER_VERSION
# @sparticuz/chromium is a DEV dependency IF YOU ARE USING A LAYER, if not, use as a production dependency!
# @sparticuz/chromium can be a DEV dependency IF YOU ARE USING A LAYER, if you are not using a layer, use as a production dependency!
npm install --save-dev @sparticuz/chromium@$CHROMIUM_VERSION
```
If your vendor does not allow large deploys (`chromium.br` is 50+ MB), you'll need to host the `chromium-v#-pack.tar` separately and use the [`@sparticuz/chromium-min` package](https://github.com/Sparticuz/chromium#-min-package).
```shell
npm install --save @sparticuz/chromium-min@$CHROMIUM_VERSION
```
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).
## Versioning
@ -36,6 +39,8 @@ If you wish to install an older version of Chromium, take a look at [@sparticuz/
The @sparticuz/chromium version schema is as follows:
`MajorChromiumVersion.MinorChromiumIncrement.@Sparticuz/chromiumPatchLevel`
Because this package follows Chromium's releases, it does NOT follow semantic versioning. **Breaking changes can occur with the 'patch' level.** Please check the release notes for information on breaking changes.
## Usage
This package works with all the currently supported AWS Lambda Node.js runtimes out of the box.
@ -45,13 +50,25 @@ const test = require("node:test");
const puppeteer = require("puppeteer-core");
const chromium = require("@sparticuz/chromium");
// 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;
// Optional: If you'd like to disable webgl, true is the default.
chromium.setGraphicsMode = false;
// Optional: Load any fonts you need. Open Sans is included by default in AWS Lambda instances
await chromium.font(
"https://raw.githack.com/googlei18n/noto-emoji/master/fonts/NotoColorEmoji.ttf"
);
test("Check the page title of example.com", async (t) => {
const browser = await puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath,
executablePath: await chromium.executablePath(),
headless: chromium.headless,
ignoreHTTPSErrors: true,
});
const page = await browser.newPage();
@ -68,13 +85,13 @@ test("Check the page title of example.com", async (t) => {
```javascript
const test = require("node:test");
// Need to rename playwright's chromium object to something else
const { chromium: playwright } = require('playwright-core');
const chromium = require('@sparticuz/chromium');
const { chromium: playwright } = require("playwright-core");
const chromium = require("@sparticuz/chromium");
test("Check the page title of example.com", async (t) => {
const browser = await playwright.launch({
args: chromium.args,
executablePath: await chromium.executablePath,
executablePath: await chromium.executablePath(),
headless: chromium.headless,
});
@ -88,38 +105,167 @@ test("Check the page title of example.com", async (t) => {
});
```
You should allocate at least 512 MB of RAM to your Lambda, however 1600 MB (or more) is recommended.
You should allocate at least 512 MB of RAM to your instance, however 1600 MB (or more) is recommended.
### Running Locally
### -min package
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.
The -min package DOES NOT include the chromium brotli files. There are a few instances where this is useful. Primarily, this is useful when your host has file size limits.
## API
To use the -min package please install the `@sparticuz/chromium-min` package.
| Method / Property | Returns | Description |
| ----------------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `font(url)` | `{?Promise<string>}` | Provisions a custom font and returns its basename. |
| `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 more sensible default viewport settings. |
| `executablePath` | `{?Promise<string>}` | Returns the path the Chromium binary was extracted to. |
| `headless` | `{!boolean}` | Returns `true` if we are running on AWS Lambda or GCF. |
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
const browser = await puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath("/opt/chromium"),
headless: chromium.headless,
});
```
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 in close proximity to your function's execution location.
On the initial iteration, `@sparticuz/chromium` will download the pack tar file, untar the files to `/tmp/chromium-pack`, then will un-brotli the `chromium` binary to `/tmp/chromium`. The following iterations will see that `/tmp/chromium` exists and will use the already downloaded files.
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,
});
```
### Examples
Here are some example projects and help with other services
- [Production Dependency](https://github.com/Sparticuz/chromium/tree/master/examples/production-dependency)
- [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)
- [Chromium-min](https://github.com/Sparticuz/chromium/tree/master/examples/remote-min-binary)
- [AWS SAM](https://github.com/Sparticuz/chromium/tree/master/examples/aws-sam)
- [Webpack](https://github.com/Sparticuz/chromium/issues/24#issuecomment-1343196897)
- [Netlify](https://github.com/Sparticuz/chromium/issues/24#issuecomment-1414107620)
### 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. Users have reported installing `rosetta` on MacOS will also work.
```shell
npx @puppeteer/browsers install chromium@latest --path /tmp/localChromium
```
For more information on installing a specific version of `chromium`, checkout [@puppeteer/browsers](https://www.npmjs.com/package/@puppeteer/browsers).
For example, you can set your code to use an ENV variable such as `IS_LOCAL`, then use if/else statements to direct puppeteer to the correct environment.
```javascript
const browser = await puppeteer.launch({
args: process.env.IS_LOCAL ? puppeteer.defaultArgs() : chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: process.env.IS_LOCAL
? "/tmp/localChromium/chromium/linux-1122391/chrome-linux/chrome"
: await chromium.executablePath(),
headless: process.env.IS_LOCAL ? false : chromium.headless,
});
```
## Frequently asked questions
### Can I use ARM or Graviton instances?
Amazon's default Lambda base image is quite old at this point and does not support newer versions of `glibc` that chromium requires. When Amazon Linux 2023 comes to Lambda as the default base image, ARM support should be possible. Ref: https://github.com/Sparticuz/chrome-aws-lambda/pull/11, https://github.com/aws/aws-lambda-base-images/issues/59
### Can I use Google Chrome or Chrome for Testing, what is headless_shell?
`headless_shell` is a purpose built version of `chromium` specific for headless purposes. It does not include the GUI at all and only works via remote debugging connection. Ref: https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md, https://source.chromium.org/chromium/chromium/src/+/main:headless/app/headless_shell.cc
### Can I use the "new" Headless mode?
From what I can tell, `headless_shell` does not seem to include support for the "new" headless mode.
### It doesn't work with Webpack!?!
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
The Amazon Linux 2 AWS Lambda runtime is no longer provisioned with any font faces.
The Amazon Linux 2 AWS Lambda runtime is not provisioned with any font faces.
Because of this, this package ships with [Open Sans](https://fonts.google.com/specimen/Open+Sans), which supports the following scripts:
* Latin
* Greek
* Cyrillic
- Latin
- Greek
- Cyrillic
To provision additional fonts, simply call the `font()` method with an absolute path or URL:
```typescript
await chromium.font('/var/task/fonts/NotoColorEmoji.ttf');
await chromium.font("/var/task/fonts/NotoColorEmoji.ttf");
// or
await chromium.font('https://raw.githack.com/googlei18n/noto-emoji/master/fonts/NotoColorEmoji.ttf');
await chromium.font(
"https://raw.githack.com/googlei18n/noto-emoji/master/fonts/NotoColorEmoji.ttf"
);
```
> `Noto Color Emoji` (or similar) is needed if you want to [render emojis](https://getemoji.com/).
@ -128,13 +274,11 @@ await chromium.font('https://raw.githack.com/googlei18n/noto-emoji/master/fonts/
This method should be invoked _before_ launching Chromium.
> On non-serverless environments, the `font()` method is a no-op to avoid polluting the user space.
---
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
@ -145,8 +289,26 @@ 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:
```shell
zip -9 --filesync --move --recurse-paths .fonts.zip .fonts/
zip -9 --filesync --move --recurse-paths fonts.zip fonts/
```
## Graphics
By default, this package uses `swiftshader`/`angle` to do CPU acceleration for WebGL. This is the only known way to enable WebGL on a serverless platform. You can disable WebGL by setting `chromium.setGraphiceMode = false;` _before_ launching Chromium. Disabling this will also skip the extract of the `bin/swiftshader.tar.br` file, which saves about a second of initial execution time. Disabling graphics is recommended if you know you are not using any WebGL.
## API
| Method / Property | Returns | Description |
| ----------------------------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `font(url)` | `Promise<string>` | Provisions a custom font and returns its basename. |
| `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. |
| `executablePath(location?: string)` | `Promise<string>` | Returns the path the Chromium binary was extracted to. |
| `setHeadlessMode` | `void` | Sets the headless mode to either `true` or `"shell"` |
| `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` |
| `graphics` | `boolean` | Returns a boolean depending on whether webgl is enabled or disabled |
## Compiling
To compile your own version of Chromium check the [Ansible playbook instructions](_/ansible).
@ -164,6 +326,7 @@ make chromium.zip
```
The above will create a `chromium.zip` file, which can be uploaded to your Layers console. You can and should upload using the `aws cli`. (Replace the variables with your own values)
```shell
bucketName="chromiumUploadBucket" && \
versionNumber="107" && \
@ -171,11 +334,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
```
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.
## Google Cloud Functions
Since version `1.11.2`, it's also possible to use this package on Google/Firebase Cloud Functions.
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.
@ -184,6 +343,8 @@ According to our benchmarks, it's 40% to 50% faster than using the off-the-shelf
- Change the import or require to be `@sparticuz/chromium`
- Add the import or require for `puppeteer-core`
- Change the browser launch to use the native `puppeteer.launch()` function
- Change the `executablePath` to be a function.
```diff
-const chromium = require('@sparticuz/chrome-aws-lambda');
+const chromium = require("@sparticuz/chromium");
@ -198,7 +359,8 @@ exports.handler = async (event, context, callback) => {
+ browser = await puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath,
- executablePath: await chromium.executablePath,
+ executablePath: await chromium.executablePath(),
headless: chromium.headless,
ignoreHTTPSErrors: true,
});
@ -219,6 +381,7 @@ exports.handler = async (event, context, callback) => {
return callback(null, result);
};
```
## Compression
The Chromium binary is compressed using the Brotli algorithm.

View File

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

View File

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

View File

@ -12,21 +12,10 @@ Resources:
LayerName: sparticuz-chromium
ContentUri: code/
CompatibleRuntimes:
- nodejs14.x
- nodejs16.x
- nodejs18.x
- nodejs20.x
node14:
Type: AWS::Serverless::Function
Properties:
Layers:
- !Ref layer
Handler: handlers/index.handler
Runtime: nodejs14.x
Policies:
- AWSLambdaBasicExecutionRole
- AWSXRayDaemonWriteAccess
Tracing: Active
node16:
Type: AWS::Serverless::Function
Properties:
@ -49,3 +38,14 @@ Resources:
- AWSLambdaBasicExecutionRole
- AWSXRayDaemonWriteAccess
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]
ansible_connection=local
ansible_python_interpreter=python
image=ami-0bc441522038d8878
image=ami-06c68f701d8090592
region=us-east-1
instance_size=c6i.12xlarge
instance_size=c7i.12xlarge
[aws]
@ -14,4 +14,4 @@ instance_size=c6i.12xlarge
ansible_connection=ssh
ansible_python_interpreter=auto_silent
ansible_ssh_private_key_file=ansible.pem
chromium_revision=1069273
chromium_revision=1343869

View File

@ -58,7 +58,7 @@
ebs:
delete_on_termination: true
volume_type: io2
volume_size: 128
volume_size: 256
iops: 3000
register: ec2
@ -71,7 +71,7 @@
wait_for:
host: "{{ ec2.instances[0].public_ip_address }}"
port: 22
timeout: 240
timeout: 320
state: started
- name: AWS
@ -88,7 +88,7 @@
become: true
become_user: root
shell: |
dnf update --releasever=2022.0.20220831 -y
dnf update --releasever=2022.0.20221207 -y
- name: Installing Packages
become: true
@ -142,8 +142,7 @@
- name: Checking for Directory Structure
stat:
path: /srv/source/chromium
register:
structure
register: structure
- name: Creating Directory Structure
become: true
@ -172,7 +171,7 @@
dest: /srv/source/chromium/.gclient
owner: ec2-user
group: ec2-user
mode: '0664'
mode: "0664"
- name: Checking for Chromium
stat:
@ -211,22 +210,22 @@
backrefs: yes
with_items:
- {
path: 'sandbox_ipc_linux.cc',
path: "sandbox_ipc_linux.cc",
line: '\1PLOG(WARNING) << "poll"; failed_polls = 0;',
regexp: '^(\s+)PLOG[(]WARNING[)] << "poll";$',
}
- {
path: 'renderer_host/render_process_host_impl.cc',
path: "renderer_host/render_process_host_impl.cc",
line: '\1// \2\3',
regexp: '^( )(\s*)(CHECK[(]render_process_host->InSameStoragePartition[(])$',
}
- {
path: 'renderer_host/render_process_host_impl.cc',
path: "renderer_host/render_process_host_impl.cc",
line: '\1// \2\3',
regexp: '^( )(\s*)(browser_context->GetStoragePartition[(]site_instance,)$',
}
- {
path: 'renderer_host/render_process_host_impl.cc',
path: "renderer_host/render_process_host_impl.cc",
line: '\1// \2\3',
regexp: '^( )(\s*)(false /[*] can_create [*]/[)][)][)];)$',
}
@ -237,14 +236,6 @@
path: /srv/source/chromium/src/out/Headless
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
args:
warn: false
- name: Creating Headless Chromium Configuration
copy:
content: |
@ -257,7 +248,6 @@
enable_keystone_registration_framework = false
enable_linux_installer = false
enable_media_remoting = false
enable_one_click_signin = false
ffmpeg_branding = "Chrome"
is_component_build = false
is_debug = false
@ -266,7 +256,6 @@
symbol_level = 0
target_cpu = "x64"
target_os = "linux"
use_brlapi = 0
use_sysroot = true
v8_symbol_level = 0
v8_target_cpu = "x64"
@ -289,7 +278,6 @@
sed --regexp-extended 's~[^0-9]+~~g' chrome/VERSION | tr '\n' '.' | sed 's~[.]$~~'
args:
chdir: /srv/source/chromium/src
warn: false
register: version
- name: Striping Symbols from Chromium Binary
@ -321,7 +309,6 @@
args:
chdir: /srv/build/chromium
creates: /srv/build/chromium/swiftshader.tar
warn: false
- name: Compressing OpenGL ES driver
shell: |
@ -346,7 +333,7 @@
amazon.aws.ec2_instance:
wait: yes
state: absent
instance_ids: '{{ ec2.instance_ids }}'
instance_ids: "{{ ec2.instance_ids }}"
region: "{{ region }}"
- name: Deleting Security Group

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.

BIN
bin/swiftshader.tar.br Executable file → Normal file

Binary file not shown.

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

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

View File

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

View File

@ -0,0 +1,29 @@
const puppeteer = require("puppeteer-core");
const chromium = require("@sparticuz/chromium");
const handler = async () => {
try {
const browser = await puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath(),
headless: chromium.headless,
ignoreHTTPSErrors: true,
});
const page = await browser.newPage();
await page.goto("https://www.example.com", { waitUntil: "networkidle0" });
console.log("Chromium:", await browser.version());
console.log("Page Title:", await page.title());
await page.close();
await browser.close();
} catch (error) {
throw new Error(error.message);
}
};
handler().then(() => console.log("Done"));

View File

@ -0,0 +1,17 @@
{
"name": "chromium-production-dependency",
"version": "0.0.0",
"description": "This package demonstrates using @sparticuz/chromium as a production dependency. WARNING: This package is over 50 megabytes and will likely not deploy using anything other than self-host",
"license": "ISC",
"author": {
"name": "Kyle McNally"
},
"main": "index.js",
"scripts": {
"test": "node index.js"
},
"dependencies": {
"@sparticuz/chromium": "110.0.0",
"puppeteer-core": "19.6.3"
}
}

View File

@ -0,0 +1,31 @@
const puppeteer = require("puppeteer-core");
const chromium = require("@sparticuz/chromium-min");
const handler = async () => {
try {
const browser = await puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath(
"https://github.com/Sparticuz/chromium/releases/download/v110.0.1/chromium-v110.0.1-pack.tar"
),
headless: chromium.headless,
ignoreHTTPSErrors: true,
});
const page = await browser.newPage();
await page.goto("https://www.example.com", { waitUntil: "networkidle0" });
console.log("Chromium:", await browser.version());
console.log("Page Title:", await page.title());
await page.close();
await browser.close();
} catch (error) {
throw new Error(error.message);
}
};
handler().then(() => console.log("Done"));

View File

@ -0,0 +1,17 @@
{
"name": "chromium-remote-min",
"version": "0.0.0",
"description": "This package demonstrates using @sparticuz/chromium-min",
"license": "ISC",
"author": {
"name": "Kyle McNally"
},
"main": "index.js",
"scripts": {
"test": "node index.js"
},
"dependencies": {
"@sparticuz/chromium-min": "110.0.1",
"puppeteer-core": "19.6.3"
}
}

View File

@ -0,0 +1,29 @@
const puppeteer = require("puppeteer-core");
const chromium = require("@sparticuz/chromium");
module.exports = {
handler: async () => {
try {
const browser = await puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath(),
headless: chromium.headless,
ignoreHTTPSErrors: true,
});
const page = await browser.newPage();
await page.goto("https://www.example.com", { waitUntil: "networkidle0" });
console.log("Chromium:", await browser.version());
console.log("Page Title:", await page.title());
await page.close();
await browser.close();
} catch (error) {
throw new Error(error.message);
}
},
};

View File

@ -0,0 +1,21 @@
{
"name": "serverless-with-lambda-layer",
"version": "0.0.0",
"description": "This package demonstrates using @sparticuz/chromium as a devDependency with a layer that contains the binaries",
"license": "ISC",
"author": {
"name": "Kyle McNally"
},
"main": "index.js",
"scripts": {
"deploy": "sls deploy",
"test": "sls invoke --function chromium-test --log"
},
"dependencies": {
"puppeteer-core": "19.6.3"
},
"devDependencies": {
"@sparticuz/chromium": "110.0.0",
"serverless": "^3.27.0"
}
}

View File

@ -0,0 +1,19 @@
service: sls-with-layer
provider:
name: aws
runtime: nodejs18.x
stage: dev
region: us-east-1
timeout: 300
functions:
chromium-test:
handler: index.handler
layers:
- !Ref ChromiumtestLambdaLayer
layers:
chromiumtest:
package:
artifact: ../../chromium.zip

View File

@ -0,0 +1,40 @@
## Upload Lambda layer to AWS
1. Download the layer zip from Github Releases
![Step 1](docs/step1.png)
2. Create a S3 bucket, or use a pre-existing bucket, upload the zip, and copy the URL
![Step 2](docs/step2.png)
3. Create a new layer or use a pre-existing layer. (If using a pre-existing layer, Create a new verion)
![Step 3](docs/step3.png)
4. Use the S3 file to load into to AWS Lambda Layers
![Step 4](docs/step4.png)
5. Add the layer to your serverless function
```yaml
service: sls-with-preexisting-layer
provider:
name: aws
runtime: nodejs18.x
stage: dev
region: us-east-1
timeout: 300
functions:
chromium-test:
handler: index.handler
layers:
- arn:aws:lambda:us-east-1:************:layer:chromium:*
```
# BONUS
These steps can easily be automated using the following code:
```shell
$ chromiumVersion="112.0.0"
$ bucketName="chromiumUploadBucket"
$ wget "https://github.com/Sparticuz/chromium/releases/download/v${chromiumVersion}/chromium-v${chromiumVersion}-layer.zip"
$ aws s3 cp "chromium-v${chromiumVersion}-layer.zip" "s3://${bucketName}/chromiumLayers/chromium-v${chromiumVersion}-layer.zip"
$ aws lambda publish-layer-version --layer-name chromium --description "Chromium v${chromiumVersion}" --content "S3Bucket=${bucketName},S3Key=chromiumLayers/chromium-v${chromiumVersion}-layer.zip" --compatible-runtimes nodejs --compatible-architectures x86_64
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 117 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

View File

@ -0,0 +1,29 @@
const puppeteer = require("puppeteer-core");
const chromium = require("@sparticuz/chromium");
module.exports = {
handler: async () => {
try {
const browser = await puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath(),
headless: chromium.headless,
ignoreHTTPSErrors: true,
});
const page = await browser.newPage();
await page.goto("https://www.example.com", { waitUntil: "networkidle0" });
console.log("Chromium:", await browser.version());
console.log("Page Title:", await page.title());
await page.close();
await browser.close();
} catch (error) {
throw new Error(error.message);
}
},
};

View File

@ -0,0 +1,21 @@
{
"name": "serverless-with-lambda-layer",
"version": "0.0.0",
"description": "This package demonstrates using @sparticuz/chromium as a devDependency with a layer that contains the binaries",
"license": "ISC",
"author": {
"name": "Kyle McNally"
},
"main": "index.js",
"scripts": {
"deploy": "sls deploy",
"test": "sls invoke --function chromium-test --log"
},
"dependencies": {
"puppeteer-core": "19.6.3"
},
"devDependencies": {
"@sparticuz/chromium": "110.0.0",
"serverless": "^3.27.0"
}
}

View File

@ -0,0 +1,14 @@
service: sls-with-layer
provider:
name: aws
runtime: nodejs18.x
stage: dev
region: us-east-1
timeout: 300
functions:
chromium-test:
handler: index.handler
layers:
- arn:aws:lambda:us-east-1:************:layer:chromium:*

View File

331
package-lock.json generated Normal file
View File

@ -0,0 +1,331 @@
{
"name": "@sparticuz/chromium",
"version": "130.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@sparticuz/chromium",
"version": "130.0.0",
"license": "MIT",
"dependencies": {
"follow-redirects": "^1.15.9",
"tar-fs": "^3.0.6"
},
"devDependencies": {
"@tsconfig/node20": "^20.1.4",
"@tsconfig/strictest": "^2.0.5",
"@types/follow-redirects": "^1.14.4",
"@types/node": "^20.16.10",
"@types/tar-fs": "^2.0.4",
"clean-modules": "^3.1.1",
"typescript": "^5.6.2"
},
"engines": {
"node": ">= 16"
}
},
"node_modules/@tsconfig/node20": {
"version": "20.1.4",
"resolved": "https://registry.npmjs.org/@tsconfig/node20/-/node20-20.1.4.tgz",
"integrity": "sha512-sqgsT69YFeLWf5NtJ4Xq/xAF8p4ZQHlmGW74Nu2tD4+g5fAsposc4ZfaaPixVu4y01BEiDCWLRDCvDM5JOsRxg==",
"dev": true
},
"node_modules/@tsconfig/strictest": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/@tsconfig/strictest/-/strictest-2.0.5.tgz",
"integrity": "sha512-ec4tjL2Rr0pkZ5hww65c+EEPYwxOi4Ryv+0MtjeaSQRJyq322Q27eOQiFbuNgw2hpL4hB1/W/HBGk3VKS43osg==",
"dev": true
},
"node_modules/@types/follow-redirects": {
"version": "1.14.4",
"resolved": "https://registry.npmjs.org/@types/follow-redirects/-/follow-redirects-1.14.4.tgz",
"integrity": "sha512-GWXfsD0Jc1RWiFmMuMFCpXMzi9L7oPDVwxUnZdg89kDNnqsRfUKXEtUYtA98A6lig1WXH/CYY/fvPW9HuN5fTA==",
"dev": true,
"dependencies": {
"@types/node": "*"
}
},
"node_modules/@types/node": {
"version": "20.16.10",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.16.10.tgz",
"integrity": "sha512-vQUKgWTjEIRFCvK6CyriPH3MZYiYlNy0fKiEYHWbcoWLEgs4opurGGKlebrTLqdSMIbXImH6XExNiIyNUv3WpA==",
"dev": true,
"license": "MIT",
"dependencies": {
"undici-types": "~6.19.2"
}
},
"node_modules/@types/tar-fs": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/@types/tar-fs/-/tar-fs-2.0.4.tgz",
"integrity": "sha512-ipPec0CjTmVDWE+QKr9cTmIIoTl7dFG/yARCM5MqK8i6CNLIG1P8x4kwDsOQY1ChZOZjH0wO9nvfgBvWl4R3kA==",
"dev": true,
"dependencies": {
"@types/node": "*",
"@types/tar-stream": "*"
}
},
"node_modules/@types/tar-stream": {
"version": "2.2.2",
"resolved": "https://registry.npmjs.org/@types/tar-stream/-/tar-stream-2.2.2.tgz",
"integrity": "sha512-1AX+Yt3icFuU6kxwmPakaiGrJUwG44MpuiqPg4dSolRFk6jmvs4b3IbUol9wKDLIgU76gevn3EwE8y/DkSJCZQ==",
"dev": true,
"dependencies": {
"@types/node": "*"
}
},
"node_modules/b4a": {
"version": "1.6.4",
"resolved": "https://registry.npmjs.org/b4a/-/b4a-1.6.4.tgz",
"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": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/clean-modules/-/clean-modules-3.1.1.tgz",
"integrity": "sha512-t/7dNtn6vQYxujYxdwZeLa0NsLE92KQ0XeV3CDJ2TXgLTvn3ijmjlQN0Dm9wjYQgC0miZiF66ClTQzgIeYw96A==",
"dev": true,
"license": "ISC",
"dependencies": {
"clipanion": "^3.2.1",
"picomatch": "^2.3.0",
"pretty-bytes": "^6.1.0",
"pretty-ms": "^8.0.0",
"supports-color": "^9.4.0"
},
"bin": {
"clean-modules": "bin/cli.js"
},
"engines": {
"node": ">=14"
}
},
"node_modules/clipanion": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/clipanion/-/clipanion-3.2.1.tgz",
"integrity": "sha512-dYFdjLb7y1ajfxQopN05mylEpK9ZX0sO1/RfMXdfmwjlIsPkbh4p7A682x++zFPLDCo1x3p82dtljHf5cW2LKA==",
"dev": true,
"dependencies": {
"typanion": "^3.8.0"
},
"peerDependencies": {
"typanion": "*"
}
},
"node_modules/end-of-stream": {
"version": "1.4.4",
"resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz",
"integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==",
"dependencies": {
"once": "^1.4.0"
}
},
"node_modules/fast-fifo": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/fast-fifo/-/fast-fifo-1.3.0.tgz",
"integrity": "sha512-IgfweLvEpwyA4WgiQe9Nx6VV2QkML2NkvZnk1oKnIzXgXdWxuhF7zw4DvLTPZJn6PIUneiAXPF24QmoEqHTjyw=="
},
"node_modules/follow-redirects": {
"version": "1.15.9",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz",
"integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==",
"funding": [
{
"type": "individual",
"url": "https://github.com/sponsors/RubenVerborgh"
}
],
"license": "MIT",
"engines": {
"node": ">=4.0"
},
"peerDependenciesMeta": {
"debug": {
"optional": true
}
}
},
"node_modules/once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==",
"dependencies": {
"wrappy": "1"
}
},
"node_modules/parse-ms": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/parse-ms/-/parse-ms-3.0.0.tgz",
"integrity": "sha512-Tpb8Z7r7XbbtBTrM9UhpkzzaMrqA2VXMT3YChzYltwV3P3pM6t8wl7TvpMnSTosz1aQAdVib7kdoys7vYOPerw==",
"dev": true,
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/picomatch": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz",
"integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==",
"dev": true,
"engines": {
"node": ">=8.6"
},
"funding": {
"url": "https://github.com/sponsors/jonschlinkert"
}
},
"node_modules/pretty-bytes": {
"version": "6.1.1",
"resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-6.1.1.tgz",
"integrity": "sha512-mQUvGU6aUFQ+rNvTIAcZuWGRT9a6f6Yrg9bHs4ImKF+HZCEK+plBvnAZYSIQztknZF2qnzNtr6F8s0+IuptdlQ==",
"dev": true,
"engines": {
"node": "^14.13.1 || >=16.0.0"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/pretty-ms": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/pretty-ms/-/pretty-ms-8.0.0.tgz",
"integrity": "sha512-ASJqOugUF1bbzI35STMBUpZqdfYKlJugy6JBziGi2EE+AL5JPJGSzvpeVXojxrr0ViUYoToUjb5kjSEGf7Y83Q==",
"dev": true,
"dependencies": {
"parse-ms": "^3.0.0"
},
"engines": {
"node": ">=14.16"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/pump": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz",
"integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==",
"dependencies": {
"end-of-stream": "^1.1.0",
"once": "^1.3.1"
}
},
"node_modules/queue-tick": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/queue-tick/-/queue-tick-1.0.1.tgz",
"integrity": "sha512-kJt5qhMxoszgU/62PLP1CJytzd2NKetjSRnyuj31fDd3Rlcz3fzlFdFLD1SItunPwyqEOkca6GbV612BWfaBag=="
},
"node_modules/streamx": {
"version": "2.15.1",
"resolved": "https://registry.npmjs.org/streamx/-/streamx-2.15.1.tgz",
"integrity": "sha512-fQMzy2O/Q47rgwErk/eGeLu/roaFWV0jVsogDmrszM9uIw8L5OA+t+V93MgYlufNptfjmYR1tOMWhei/Eh7TQA==",
"dependencies": {
"fast-fifo": "^1.1.0",
"queue-tick": "^1.0.1"
}
},
"node_modules/supports-color": {
"version": "9.4.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-9.4.0.tgz",
"integrity": "sha512-VL+lNrEoIXww1coLPOmiEmK/0sGigko5COxI09KzHc2VJXJsQ37UaQ+8quuxjDeA7+KnLGTWRyOXSLLR2Wb4jw==",
"dev": true,
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/chalk/supports-color?sponsor=1"
}
},
"node_modules/tar-fs": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-3.0.6.tgz",
"integrity": "sha512-iokBDQQkUyeXhgPYaZxmczGPhnhXZ0CmrqI+MOb/WFGS9DW5wnfrLgtjUJBvz50vQ3qfRwJ62QVoCFu8mPVu5w==",
"dependencies": {
"pump": "^3.0.0",
"tar-stream": "^3.1.5"
},
"optionalDependencies": {
"bare-fs": "^2.1.1",
"bare-path": "^2.1.0"
}
},
"node_modules/tar-stream": {
"version": "3.1.6",
"resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-3.1.6.tgz",
"integrity": "sha512-B/UyjYwPpMBv+PaFSWAmtYjwdrlEaZQEhMIBFNC5oEG8lpiW8XjcSdmEaClj28ArfKScKHs2nshz3k2le6crsg==",
"dependencies": {
"b4a": "^1.6.4",
"fast-fifo": "^1.2.0",
"streamx": "^2.15.0"
}
},
"node_modules/typanion": {
"version": "3.14.0",
"resolved": "https://registry.npmjs.org/typanion/-/typanion-3.14.0.tgz",
"integrity": "sha512-ZW/lVMRabETuYCd9O9ZvMhAh8GslSqaUjxmK/JLPCh6l73CvLBiuXswj/+7LdnWOgYsQ130FqLzFz5aGT4I3Ug==",
"dev": true
},
"node_modules/typescript": {
"version": "5.6.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.2.tgz",
"integrity": "sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==",
"dev": true,
"license": "Apache-2.0",
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
},
"engines": {
"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": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="
}
}
}

View File

@ -1,41 +1,7 @@
{
"name": "@sparticuz/chromium",
"version": "109.0.0",
"author": {
"name": "Kyle McNally"
},
"license": "MIT",
"version": "130.0.0",
"description": "Chromium Binary for Serverless Platforms",
"main": "build/index.js",
"types": "build/index.d.ts",
"files": [
"bin",
"build"
],
"engines": {
"node": ">= 14"
},
"scripts": {
"test": "make clean && make && make pretest && make test",
"build": "rm -rf build && tsc -p tsconfig.json",
"postversion": "git push && git push --tags && npm publish",
"prepack": "npm run build",
"preversion": "npm run build"
},
"devDependencies": {
"@types/node": "^16.11.62",
"@types/tar-fs": "^2.0.1",
"clean-modules": "^2.0.6",
"typescript": "^4.8.3"
},
"bugs": {
"url": "https://github.com/Sparticuz/chromium/issues"
},
"homepage": "https://github.com/Sparticuz/chromium",
"repository": {
"type": "git",
"url": "git://github.com/Sparticuz/chromium.git"
},
"keywords": [
"aws",
"browser",
@ -46,18 +12,43 @@
"playwright",
"serverless"
],
"prettier": {
"arrowParens": "always",
"bracketSpacing": true,
"jsxBracketSameLine": false,
"printWidth": 140,
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false
"homepage": "https://github.com/Sparticuz/chromium",
"bugs": {
"url": "https://github.com/Sparticuz/chromium/issues"
},
"repository": {
"type": "git",
"url": "git://github.com/Sparticuz/chromium.git"
},
"license": "MIT",
"author": {
"name": "Kyle McNally"
},
"type": "commonjs",
"main": "build/index.js",
"types": "build/index.d.ts",
"files": [
"bin",
"build"
],
"scripts": {
"build": "rm -rf build && tsc -p tsconfig.json",
"test": "make clean && make && make pretest && make test"
},
"dependencies": {
"tar-fs": "^2.1.1"
"follow-redirects": "^1.15.9",
"tar-fs": "^3.0.6"
},
"devDependencies": {
"@tsconfig/node20": "^20.1.4",
"@tsconfig/strictest": "^2.0.5",
"@types/follow-redirects": "^1.14.4",
"@types/node": "^20.16.10",
"@types/tar-fs": "^2.0.4",
"clean-modules": "^3.1.1",
"typescript": "^5.6.2"
},
"engines": {
"node": ">= 16"
}
}

76
source/helper.ts Normal file
View File

@ -0,0 +1,76 @@
import { unlink } from "node:fs";
import { https } from "follow-redirects";
import { tmpdir } from "node:os";
import { extract } from "tar-fs";
import { parse } from "node:url";
import type { UrlWithStringQuery } from "node:url";
interface FollowRedirOptions extends UrlWithStringQuery {
maxBodyLength: number;
}
export const isValidUrl = (input: string) => {
try {
return !!new URL(input);
} catch (err) {
return false;
}
};
/**
* Determines if the running instance is inside an AWS Lambda container.
* AWS_EXECUTION_ENV is for native Lambda instances
* AWS_LAMBDA_JS_RUNTIME is for netlify instances
* @returns boolean indicating if the running instance is inside a Lambda container
*/
export const isRunningInAwsLambda = () => {
if (
process.env["AWS_EXECUTION_ENV"] &&
process.env["AWS_EXECUTION_ENV"].includes("AWS_Lambda_nodejs") &&
!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("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 false;
};
export const downloadAndExtract = async (url: string) =>
new Promise<string>((resolve, reject) => {
const getOptions = parse(url) as FollowRedirOptions;
getOptions.maxBodyLength = 60 * 1024 * 1024; // 60mb
const destDir = `${tmpdir()}/chromium-pack`;
const extractObj = extract(destDir);
https
.get(url, (response) => {
response.pipe(extractObj);
extractObj.on("finish", () => {
resolve(destDir);
});
})
.on("error", (err) => {
unlink(destDir, (_) => {
reject(err);
});
});
});

View File

@ -1,8 +1,20 @@
import { access, createWriteStream, existsSync, mkdirSync, readdirSync, symlink, unlinkSync } from 'fs';
import { IncomingMessage } from 'http';
import LambdaFS from './lambdafs';
import { join } from 'path';
import { URL } from 'url';
import {
access,
createWriteStream,
existsSync,
mkdirSync,
symlink,
} from "node:fs";
import { https } from "follow-redirects";
import LambdaFS from "./lambdafs";
import { join } from "node:path";
import { URL } from "node:url";
import {
downloadAndExtract,
isRunningInAwsLambda,
isValidUrl,
isRunningInAwsLambdaNode20,
} from "./helper";
/** Viewport taken from https://github.com/puppeteer/puppeteer/blob/main/docs/api/puppeteer.viewport.md */
interface Viewport {
@ -17,54 +29,89 @@ interface Viewport {
/**
* Specify device scale factor.
* See {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio | devicePixelRatio} for more info.
* @defaultValue 1
* @default 1
*/
deviceScaleFactor?: number;
/**
* Whether the `meta viewport` tag is taken into account.
* @defaultValue false
* @default false
*/
isMobile?: boolean;
/**
* Specifies if the viewport is in landscape mode.
* @defaultValue false
* @default false
*/
isLandscape?: boolean;
/**
* Specify if the viewport supports touch events.
* @defaultValue false
* @default false
*/
hasTouch?: boolean;
}
if (/^AWS_Lambda_nodejs(?:10|12|14|16|18)[.]x$/.test(process.env.AWS_EXECUTION_ENV) === true) {
if (process.env.FONTCONFIG_PATH === undefined) {
process.env.FONTCONFIG_PATH = '/tmp/aws';
if (isRunningInAwsLambda()) {
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/aws/lib';
} else if (process.env.LD_LIBRARY_PATH.startsWith('/tmp/aws/lib') !== true) {
process.env.LD_LIBRARY_PATH = [...new Set(['/tmp/aws/lib', ...process.env.LD_LIBRARY_PATH.split(':')])].join(':');
if (process.env["LD_LIBRARY_PATH"] === undefined) {
process.env["LD_LIBRARY_PATH"] = "/tmp/al2/lib";
} else if (
process.env["LD_LIBRARY_PATH"].startsWith("/tmp/al2/lib") !== true
) {
process.env["LD_LIBRARY_PATH"] = [
...new Set([
"/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(":"),
]),
].join(":");
}
}
class Chromium {
/**
* Determines the headless mode that chromium will run at
* https://developer.chrome.com/articles/new-headless/#try-out-the-new-headless
* @values true or "new"
*/
private static headlessMode: true | "shell" = "shell";
/**
* If true, the graphics stack and webgl is enabled,
* If false, webgl will be disabled.
* (If false, the swiftshader.tar.br file will also not extract)
*/
private static graphicsMode: boolean = true;
/**
* Downloads or symlinks a custom font and returns its basename, patching the environment so that Chromium can find it.
* If not running on AWS Lambda nor Google Cloud Functions, `null` is returned instead.
*/
static font(input: string): Promise<string> {
if (Chromium.headless !== true) {
return null;
if (process.env["HOME"] === undefined) {
process.env["HOME"] = "/tmp";
}
if (process.env.HOME === undefined) {
process.env.HOME = '/tmp';
}
if (existsSync(`${process.env.HOME}/.fonts`) !== true) {
mkdirSync(`${process.env.HOME}/.fonts`);
if (existsSync(`${process.env["HOME"]}/.fonts`) !== true) {
mkdirSync(`${process.env["HOME"]}/.fonts`);
}
return new Promise((resolve, reject) => {
@ -73,43 +120,45 @@ class Chromium {
}
const url = new URL(input);
const output = `${process.env.HOME}/.fonts/${url.pathname.split('/').pop()}`;
const output = `${process.env["HOME"]}/.fonts/${url.pathname
.split("/")
.pop()}`;
if (existsSync(output) === true) {
return resolve(output.split('/').pop());
return resolve(output.split("/").pop() as string);
}
if (url.protocol === 'file:') {
if (url.protocol === "file:") {
access(url.pathname, (error) => {
if (error != null) {
return reject(error);
}
symlink(url.pathname, output, (error) => {
return error != null ? reject(error) : resolve(url.pathname.split('/').pop());
return error != null
? reject(error)
: resolve(url.pathname.split("/").pop() as string);
});
});
} else {
let handler = url.protocol === 'http:' ? require('http').get : require('https').get;
handler(input, (response: IncomingMessage) => {
https.get(input, (response) => {
if (response.statusCode !== 200) {
return reject(`Unexpected status code: ${response.statusCode}.`);
}
const stream = createWriteStream(output);
stream.once('error', (error) => {
stream.once("error", (error) => {
return reject(error);
});
response.on('data', (chunk) => {
response.on("data", (chunk) => {
stream.write(chunk);
});
response.once('end', () => {
response.once("end", () => {
stream.end(() => {
return resolve(url.pathname.split('/').pop());
return resolve(url.pathname.split("/").pop() as string);
});
});
});
@ -122,47 +171,113 @@ class Chromium {
* The canonical list of flags can be found on https://peter.sh/experiments/chromium-command-line-switches/.
*/
static get args(): string[] {
const result = [
'--allow-running-insecure-content', // https://source.chromium.org/search?q=lang:cpp+symbol:kAllowRunningInsecureContent&ss=chromium
'--autoplay-policy=user-gesture-required', // https://source.chromium.org/search?q=lang:cpp+symbol:kAutoplayPolicy&ss=chromium
'--disable-background-timer-throttling',
'--disable-component-update', // https://source.chromium.org/search?q=lang:cpp+symbol:kDisableComponentUpdate&ss=chromium
'--disable-domain-reliability', // https://source.chromium.org/search?q=lang:cpp+symbol:kDisableDomainReliability&ss=chromium
'--disable-features=AudioServiceOutOfProcess,IsolateOrigins,site-per-process', // https://source.chromium.org/search?q=file:content_features.cc&ss=chromium
'--disable-ipc-flooding-protection',
'--disable-print-preview', // https://source.chromium.org/search?q=lang:cpp+symbol:kDisablePrintPreview&ss=chromium
'--disable-dev-shm-usage',
'--disable-setuid-sandbox', // https://source.chromium.org/search?q=lang:cpp+symbol:kDisableSetuidSandbox&ss=chromium
'--disable-site-isolation-trials', // https://source.chromium.org/search?q=lang:cpp+symbol:kDisableSiteIsolation&ss=chromium
'--disable-speech-api', // https://source.chromium.org/search?q=lang:cpp+symbol:kDisableSpeechAPI&ss=chromium
'--disable-web-security', // https://source.chromium.org/search?q=lang:cpp+symbol:kDisableWebSecurity&ss=chromium
'--disk-cache-size=33554432', // https://source.chromium.org/search?q=lang:cpp+symbol:kDiskCacheSize&ss=chromium
'--enable-features=SharedArrayBuffer', // https://source.chromium.org/search?q=file:content_features.cc&ss=chromium
'--hide-scrollbars', // https://source.chromium.org/search?q=lang:cpp+symbol:kHideScrollbars&ss=chromium
'--ignore-gpu-blocklist', // https://source.chromium.org/search?q=lang:cpp+symbol:kIgnoreGpuBlocklist&ss=chromium
'--in-process-gpu', // https://source.chromium.org/search?q=lang:cpp+symbol:kInProcessGPU&ss=chromium
'--mute-audio', // https://source.chromium.org/search?q=lang:cpp+symbol:kMuteAudio&ss=chromium
'--no-default-browser-check', // https://source.chromium.org/search?q=lang:cpp+symbol:kNoDefaultBrowserCheck&ss=chromium
'--no-first-run',
'--no-pings', // https://source.chromium.org/search?q=lang:cpp+symbol:kNoPings&ss=chromium
'--no-sandbox', // https://source.chromium.org/search?q=lang:cpp+symbol:kNoSandbox&ss=chromium
'--no-zygote', // https://source.chromium.org/search?q=lang:cpp+symbol:kNoZygote&ss=chromium
'--use-gl=angle', // https://chromium.googlesource.com/chromium/src/+/main/docs/gpu/swiftshader.md
'--use-angle=swiftshader', // https://chromium.googlesource.com/chromium/src/+/main/docs/gpu/swiftshader.md
'--window-size=1920,1080', // https://source.chromium.org/search?q=lang:cpp+symbol:kWindowSize&ss=chromium
/**
* These are the default args in puppeteer.
* https://github.com/puppeteer/puppeteer/blob/3a31070d054fa3cd8116ca31c578807ed8d6f987/packages/puppeteer-core/src/node/ChromeLauncher.ts#L185
*/
const puppeteerFlags = [
"--allow-pre-commit-input",
"--disable-background-networking",
"--disable-background-timer-throttling",
"--disable-backgrounding-occluded-windows",
"--disable-breakpad",
"--disable-client-side-phishing-detection",
"--disable-component-extensions-with-background-pages",
"--disable-component-update",
"--disable-default-apps",
"--disable-dev-shm-usage",
"--disable-extensions",
"--disable-hang-monitor",
"--disable-ipc-flooding-protection",
"--disable-popup-blocking",
"--disable-prompt-on-repost",
"--disable-renderer-backgrounding",
"--disable-sync",
"--enable-automation",
// TODO(sadym): remove '--enable-blink-features=IdleDetection' once
// IdleDetection is turned on by default.
"--enable-blink-features=IdleDetection",
"--export-tagged-pdf",
"--force-color-profile=srgb",
"--metrics-recording-only",
"--no-first-run",
"--password-store=basic",
"--use-mock-keychain",
];
const puppeteerDisableFeatures = [
"Translate",
"BackForwardCache",
// AcceptCHFrame disabled because of crbug.com/1348106.
"AcceptCHFrame",
"MediaRouter",
"OptimizationHints",
];
const puppeteerEnableFeatures = ["NetworkServiceInProcess2"];
const chromiumFlags = [
"--disable-domain-reliability", // https://github.com/GoogleChrome/chrome-launcher/blob/main/docs/chrome-flags-for-tools.md#background-networking
"--disable-print-preview", // https://source.chromium.org/search?q=lang:cpp+symbol:kDisablePrintPreview&ss=chromium
"--disable-speech-api", // https://source.chromium.org/search?q=lang:cpp+symbol:kDisableSpeechAPI&ss=chromium
"--disk-cache-size=33554432", // https://source.chromium.org/search?q=lang:cpp+symbol:kDiskCacheSize&ss=chromium
"--mute-audio", // https://source.chromium.org/search?q=lang:cpp+symbol:kMuteAudio&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
"--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 = [
"AudioServiceOutOfProcess",
"IsolateOrigins",
"site-per-process",
];
const chromiumEnableFeatures = ["SharedArrayBuffer"];
const graphicsFlags = [
"--hide-scrollbars", // https://source.chromium.org/search?q=lang:cpp+symbol:kHideScrollbars&ss=chromium
"--ignore-gpu-blocklist", // https://source.chromium.org/search?q=lang:cpp+symbol:kIgnoreGpuBlocklist&ss=chromium
"--in-process-gpu", // https://source.chromium.org/search?q=lang:cpp+symbol:kInProcessGPU&ss=chromium
"--window-size=1920,1080", // https://source.chromium.org/search?q=lang:cpp+symbol:kWindowSize&ss=chromium
];
if (Chromium.headless === true) {
result.push('--single-process'); // https://source.chromium.org/search?q=lang:cpp+symbol:kSingleProcess&ss=chromium
} else {
result.push('--start-maximized'); // https://source.chromium.org/search?q=lang:cpp+symbol:kStartMaximized&ss=chromium
}
// https://chromium.googlesource.com/chromium/src/+/main/docs/gpu/swiftshader.md
// Blocked by https://github.com/Sparticuz/chromium/issues/247
//this.graphics
// ? graphicsFlags.push("--use-gl=angle", "--use-angle=swiftshader")
// : graphicsFlags.push("--disable-webgl");
graphicsFlags.push("--use-gl=angle", "--use-angle=swiftshader");
return result;
const insecureFlags = [
"--allow-running-insecure-content", // https://source.chromium.org/search?q=lang:cpp+symbol:kAllowRunningInsecureContent&ss=chromium
"--disable-setuid-sandbox", // https://source.chromium.org/search?q=lang:cpp+symbol:kDisableSetuidSandbox&ss=chromium
"--disable-site-isolation-trials", // https://source.chromium.org/search?q=lang:cpp+symbol:kDisableSiteIsolation&ss=chromium
"--disable-web-security", // https://source.chromium.org/search?q=lang:cpp+symbol:kDisableWebSecurity&ss=chromium
"--no-sandbox", // https://source.chromium.org/search?q=lang:cpp+symbol:kNoSandbox&ss=chromium
"--no-zygote", // https://source.chromium.org/search?q=lang:cpp+symbol:kNoZygote&ss=chromium
];
const headlessFlags = [
this.headless === "shell" ? "--headless='shell'" : "--headless",
];
return [
...puppeteerFlags,
...chromiumFlags,
`--disable-features=${[
...puppeteerDisableFeatures,
...chromiumDisableFeatures,
].join(",")}`,
`--enable-features=${[
...puppeteerEnableFeatures,
...chromiumEnableFeatures,
].join(",")}`,
...graphicsFlags,
...insecureFlags,
...headlessFlags,
];
}
/**
* Returns sensible default viewport settings.
* Returns sensible default viewport settings for serverless environments.
*/
static get defaultViewport(): Required<Viewport> {
return {
@ -176,53 +291,120 @@ class Chromium {
}
/**
* Inflates the current version of Chromium and returns the path to the binary.
* If not running on AWS Lambda nor Google Cloud Functions, `null` is returned instead.
* Inflates the included version of Chromium
* @param input The location of the `bin` folder
* @returns The path to the `chromium` binary
*/
static get executablePath(): Promise<string> {
if (existsSync('/tmp/chromium') === true) {
for (const file of readdirSync('/tmp')) {
if (file.startsWith('core.chromium') === true) {
unlinkSync(`/tmp/${file}`);
}
}
return Promise.resolve('/tmp/chromium');
}
const input = join(__dirname, '..', 'bin');
const promises = [
LambdaFS.inflate(`${input}/chromium.br`),
LambdaFS.inflate(`${input}/swiftshader.tar.br`),
];
if (/^AWS_Lambda_nodejs(?:10|12|14|16|18)[.]x$/.test(process.env.AWS_EXECUTION_ENV) === true) {
promises.push(LambdaFS.inflate(`${input}/aws.tar.br`));
}
return Promise.all(promises).then((result) => result.shift());
static async executablePath(input?: string): Promise<string> {
/**
* If the `chromium` binary already exists in /tmp/chromium, return it.
*/
if (existsSync("/tmp/chromium") === true) {
return Promise.resolve("/tmp/chromium");
}
/**
* Returns a boolean indicating if we are running on AWS Lambda or Google Cloud Functions.
* True is returned if the NODE_ENV is set to 'test' for easier integration testing.
* False is returned if Serverless environment variables `IS_LOCAL` or `IS_OFFLINE` are set.
* If input is a valid URL, download and extract the file. It will extract to /tmp/chromium-pack
* and executablePath will be recursively called on that location, which will then extract
* the brotli files to the correct locations
*/
static get headless() {
if (process.env.IS_LOCAL !== undefined || process.env.IS_OFFLINE !== undefined) {
return false;
if (input && isValidUrl(input)) {
return this.executablePath(await downloadAndExtract(input));
}
if (process.env.NODE_ENV === "test") {
return true;
}
const environments = [
'AWS_LAMBDA_FUNCTION_NAME',
'FUNCTION_NAME',
'FUNCTION_TARGET',
'FUNCTIONS_EMULATOR',
];
return environments.some((key) => process.env[key] !== undefined);
/**
* If input is defined, use that as the location of the brotli files,
* otherwise, the default location is ../bin.
* A custom location is needed for workflows that using custom packaging.
*/
input ??= join(__dirname, "..", "bin");
/**
* If the input directory doesn't exist, throw an error.
*/
if (!existsSync(input)) {
throw new Error(`The input directory "${input}" does not exist.`);
}
// Extract the required files
const promises = [
LambdaFS.inflate(`${input}/chromium.br`),
LambdaFS.inflate(`${input}/fonts.tar.br`),
];
if (this.graphics) {
// Only inflate graphics stack if needed
promises.push(LambdaFS.inflate(`${input}/swiftshader.tar.br`));
}
if (isRunningInAwsLambda()) {
// If running in AWS Lambda, extract more required files
promises.push(LambdaFS.inflate(`${input}/al2.tar.br`));
}
if (isRunningInAwsLambdaNode20()) {
promises.push(LambdaFS.inflate(`${input}/al2023.tar.br`));
}
// Await all extractions
const result = await Promise.all(promises);
// Returns the first result of the promise, which is the location of the `chromium` binary
return result.shift() as string;
}
/**
* Returns the headless mode.
* "shell" means the 'old' (legacy, chromium < 112) headless mode.
* `true` means the 'new' headless mode.
* https://developer.chrome.com/articles/new-headless/#try-out-the-new-headless
* @returns true | "shell"
*/
public static get headless() {
return this.headlessMode;
}
/**
* Sets the headless mode.
* "shell" means the 'old' (legacy, chromium < 112) headless mode.
* `true` means the 'new' headless mode.
* https://developer.chrome.com/articles/new-headless/#try-out-the-new-headless
* @default "shell"
*/
public static set setHeadlessMode(value: true | "shell") {
if (
(typeof value === "string" && value !== "shell") ||
(typeof value === "boolean" && value !== true)
) {
throw new Error(
`Headless mode must be either \`true\` or 'shell', you entered '${value}'`
);
}
this.headlessMode = value;
}
/**
* Returns whether the graphics stack is enabled or disabled
* @returns boolean
*/
public static get graphics() {
return this.graphicsMode;
}
/**
* Sets whether the graphics stack is enabled or disabled.
* @param true means the stack is enabled. WebGL will work.
* @param false means that the stack is disabled. WebGL will not work.
* `false` will also skip the extract of the graphics driver, saving about a second during initial extract
* @default true
*/
public static set setGraphicsMode(value: boolean) {
if (typeof value !== "boolean") {
throw new Error(
`Graphics mode must be a boolean, you entered '${value}'`
);
}
// Disabling 'disabling the gpu'
// Blocked by https://github.com/Sparticuz/chromium/issues/247
// this.graphicsMode = value;
this.graphicsMode = true;
}
}

View File

@ -1,8 +1,8 @@
import { createReadStream, createWriteStream, existsSync } from 'fs';
import { tmpdir } from 'os';
import { basename, join } from 'path';
import { extract } from 'tar-fs';
import { createBrotliDecompress, createUnzip } from 'zlib';
import { createReadStream, createWriteStream, existsSync } from "node:fs";
import { tmpdir } from "node:os";
import { basename, join } from "node:path";
import { extract } from "tar-fs";
import { createBrotliDecompress, createUnzip } from "node:zlib";
class LambdaFS {
/**
@ -11,7 +11,15 @@ class LambdaFS {
* @param filePath Path of the file to decompress.
*/
static inflate(filePath: string): Promise<string> {
const output = filePath.includes("swiftshader") ? tmpdir() : join(tmpdir(), basename(filePath).replace(/[.](?:t(?:ar(?:[.](?:br|gz))?|br|gz)|br|gz)$/i, ''));
const output = filePath.includes("swiftshader")
? tmpdir()
: join(
tmpdir(),
basename(filePath).replace(
/[.](?:t(?:ar(?:[.](?:br|gz))?|br|gz)|br|gz)$/i,
""
)
);
return new Promise((resolve, reject) => {
if (filePath.includes("swiftshader")) {
@ -30,27 +38,33 @@ class LambdaFS {
if (/[.](?:t(?:ar(?:[.](?:br|gz))?|br|gz))$/i.test(filePath) === true) {
target = extract(output);
target.once('finish', () => {
target.once("finish", () => {
return resolve(output);
});
} else {
target = createWriteStream(output, { mode: 0o700 });
}
source.once('error', (error: Error) => {
source.once("error", (error: Error) => {
return reject(error);
});
target.once('error', (error: Error) => {
target.once("error", (error: Error) => {
return reject(error);
});
target.once('close', () => {
target.once("close", () => {
return resolve(output);
});
if (/(?:br|gz)$/i.test(filePath) === true) {
source.pipe(/br$/i.test(filePath) ? createBrotliDecompress({ chunkSize: 2 ** 21 }) : createUnzip({ chunkSize: 2 ** 21 })).pipe(target);
source
.pipe(
/br$/i.test(filePath)
? createBrotliDecompress({ chunkSize: 2 ** 21 })
: createUnzip({ chunkSize: 2 ** 21 })
)
.pipe(target);
} else {
source.pipe(target);
}
@ -58,4 +72,4 @@ class LambdaFS {
}
}
export = LambdaFS;
export default LambdaFS;

View File

@ -1,41 +1,11 @@
{
"compileOnSave": false,
"extends": ["@tsconfig/node20/tsconfig", "@tsconfig/strictest"],
"compilerOptions": {
"alwaysStrict": true,
"declaration": true,
"declarationDir": "build",
"emitDecoratorMetadata": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"importHelpers": false,
"inlineSourceMap": false,
"lib": ["dom", "es2020"],
"listEmittedFiles": false,
"listFiles": false,
"module": "commonjs",
"moduleResolution": "node",
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"outDir": "build",
"pretty": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"strictFunctionTypes": true,
"strictNullChecks": false,
"target": "es2020",
"traceResolution": false,
"types": ["node"]
"lib": ["dom", "ES2023"],
"module": "NodeNext",
"moduleResolution": "NodeNext",
"outDir": "build"
},
"exclude": ["build", "node_modules", "tmp"],
"include": ["source"],
"typeAcquisition": {
"enable": true
}
"include": ["source"]
}