Compare commits
No commits in common. "master" and "v119.0.1-next.0" have entirely different histories.
master
...
v119.0.1-n
|
|
@ -29,7 +29,7 @@ jobs:
|
|||
run: make chromium.zip
|
||||
|
||||
- name: Upload Layer Artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: chromium
|
||||
path: chromium.zip
|
||||
|
|
@ -51,7 +51,7 @@ jobs:
|
|||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v5
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: "3.x"
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ jobs:
|
|||
uses: aws-actions/setup-sam@v2
|
||||
|
||||
- name: Download Layer Artifact
|
||||
uses: actions/download-artifact@v4
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: chromium
|
||||
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ jobs:
|
|||
cd ..
|
||||
|
||||
- name: Upload items to Github Release
|
||||
uses: ncipollo/release-action@v1.14.0
|
||||
uses: ncipollo/release-action@v1.13.0
|
||||
with:
|
||||
tag: ${{ github.ref_name }}
|
||||
body: |
|
||||
|
|
|
|||
|
|
@ -12,4 +12,3 @@ _/amazon/.aws-sam
|
|||
*.tgz
|
||||
examples/**/package-lock.json
|
||||
examples/**/.serverless
|
||||
docker
|
||||
|
|
|
|||
9
Makefile
9
Makefile
|
|
@ -10,17 +10,14 @@ pretest:
|
|||
test:
|
||||
sam local invoke --template _/amazon/template.yml --event _/amazon/events/example.com.json node20
|
||||
|
||||
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
|
||||
.fonts.zip:
|
||||
zip -9 --filesync --move --recurse-paths .fonts.zip .fonts/
|
||||
|
||||
%.zip:
|
||||
npm install --fund=false --package-lock=false
|
||||
npm run build
|
||||
mkdir -p nodejs
|
||||
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 install --prefix nodejs/ tar-fs@2.1.1 follow-redirects@1.15.2 --bin-links=false --fund=false --omit=optional --omit=dev --package-lock=false --save=false
|
||||
npm pack
|
||||
mkdir -p nodejs/node_modules/@sparticuz/chromium/
|
||||
tar --directory nodejs/node_modules/@sparticuz/chromium/ --extract --file sparticuz-chromium-*.tgz --strip-components=1
|
||||
|
|
|
|||
58
README.md
58
README.md
|
|
@ -50,9 +50,7 @@ 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.
|
||||
// Optional: If you'd like to use the legacy headless mode. "new" is the default.
|
||||
chromium.setHeadlessMode = true;
|
||||
|
||||
// Optional: If you'd like to disable webgl, true is the default.
|
||||
|
|
@ -165,7 +163,7 @@ Here are some example projects and help with other services
|
|||
|
||||
### 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.
|
||||
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.
|
||||
|
||||
```shell
|
||||
npx @puppeteer/browsers install chromium@latest --path /tmp/localChromium
|
||||
|
|
@ -204,50 +202,6 @@ From what I can tell, `headless_shell` does not seem to include support for the
|
|||
|
||||
Try marking this package as an external. Ref: https://webpack.js.org/configuration/externals/
|
||||
|
||||
### 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 not provisioned with any font faces.
|
||||
|
|
@ -278,7 +232,7 @@ This method should be invoked _before_ launching Chromium.
|
|||
|
||||
Alternatively, it's also possible to provision fonts via AWS Lambda Layers.
|
||||
|
||||
Simply create a directory named `.fonts` or `fonts` and place any font faces you want there:
|
||||
Simply create a directory named `.fonts` and place any font faces you want there:
|
||||
|
||||
```
|
||||
.fonts
|
||||
|
|
@ -289,7 +243,7 @@ Simply create a directory named `.fonts` or `fonts` and place any font faces you
|
|||
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
|
||||
|
|
@ -304,8 +258,8 @@ By default, this package uses `swiftshader`/`angle` to do CPU acceleration for W
|
|||
| `args` | `Array<string>` | Provides a list of recommended additional [Chromium flags](https://github.com/GoogleChrome/chrome-launcher/blob/master/docs/chrome-flags-for-tools.md). |
|
||||
| `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 |
|
||||
| `setHeadlessMode` | `void` | Sets the headless mode to either `true` or `"new"` |
|
||||
| `headless` | `true \| "new"` | Returns `true` or `"new"` 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 |
|
||||
|
||||
|
|
|
|||
|
|
@ -3,14 +3,21 @@
|
|||
"url": "https://example.com",
|
||||
"expected": {
|
||||
"title": "Example Domain",
|
||||
"screenshot": "e610a8be5568f23c453b08928460aae3ae0b4b0a"
|
||||
"screenshot": "fdd55bf210cb00e00cadf3098055611d11293d02"
|
||||
}
|
||||
},
|
||||
{
|
||||
"url": "https://example.com",
|
||||
"expected": {
|
||||
"title": "Example Domain",
|
||||
"screenshot": "fdd55bf210cb00e00cadf3098055611d11293d02"
|
||||
}
|
||||
},
|
||||
{
|
||||
"url": "https://get.webgl.org",
|
||||
"expected": {
|
||||
"remove": "logo-container",
|
||||
"screenshot": "ec6c79a571b4cb5727c6fc23f9da30de3868138c"
|
||||
"screenshot": "7a63a9a18f32dcdad78e1e0a03364fade25c85a8"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
const { ok } = require("node:assert");
|
||||
const { createHash } = require("node:crypto");
|
||||
const { ok } = require("assert");
|
||||
const { createHash } = require("crypto");
|
||||
const puppeteer = require("puppeteer-core");
|
||||
const chromium = require("@sparticuz/chromium");
|
||||
|
||||
|
|
@ -10,16 +10,22 @@ exports.handler = async (event, context) => {
|
|||
browser = await puppeteer.launch({
|
||||
args: chromium.args,
|
||||
defaultViewport: chromium.defaultViewport,
|
||||
dumpio: true,
|
||||
executablePath: await chromium.executablePath(),
|
||||
headless: chromium.headless,
|
||||
acceptInsecureCerts: true,
|
||||
ignoreHTTPSErrors: true,
|
||||
});
|
||||
|
||||
console.log("Chromium version", await browser.version());
|
||||
console.log("Chromium verion", await browser.version());
|
||||
|
||||
for (let job of event) {
|
||||
const page = await browser.newPage();
|
||||
const contexts = [browser.defaultBrowserContext()];
|
||||
|
||||
while (contexts.length < event.length) {
|
||||
contexts.push(await browser.createIncognitoBrowserContext());
|
||||
}
|
||||
|
||||
for (let context of contexts) {
|
||||
const job = event.shift();
|
||||
const page = await context.newPage();
|
||||
|
||||
if (job.hasOwnProperty("url") === true) {
|
||||
await page.goto(job.url, { waitUntil: ["domcontentloaded", "load"] });
|
||||
|
|
@ -38,15 +44,8 @@ exports.handler = async (event, context) => {
|
|||
document.getElementById(selector).remove();
|
||||
}, job.expected.remove);
|
||||
}
|
||||
const screenshot = Buffer.from(await page.screenshot());
|
||||
/*
|
||||
console.log(
|
||||
`data:image/png;base64,${screenshot.toString("base64")}`,
|
||||
createHash("sha1")
|
||||
.update(screenshot.toString("base64"))
|
||||
.digest("hex")
|
||||
);
|
||||
*/
|
||||
const screenshot = await page.screenshot();
|
||||
// console.log(screenshot.toString('base64'), createHash('sha1').update(screenshot.toString('base64')).digest('hex'));
|
||||
ok(
|
||||
createHash("sha1")
|
||||
.update(screenshot.toString("base64"))
|
||||
|
|
@ -61,9 +60,6 @@ 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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ Resources:
|
|||
CompatibleRuntimes:
|
||||
- nodejs16.x
|
||||
- nodejs18.x
|
||||
- nodejs20.x
|
||||
|
||||
node16:
|
||||
Type: AWS::Serverless::Function
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@
|
|||
[localhost:vars]
|
||||
ansible_connection=local
|
||||
ansible_python_interpreter=python
|
||||
image=ami-06c68f701d8090592
|
||||
image=ami-08d090f841c8435e9
|
||||
region=us-east-1
|
||||
instance_size=c7i.12xlarge
|
||||
instance_size=c6i.12xlarge
|
||||
|
||||
[aws]
|
||||
|
||||
|
|
@ -14,4 +14,4 @@ instance_size=c7i.12xlarge
|
|||
ansible_connection=ssh
|
||||
ansible_python_interpreter=auto_silent
|
||||
ansible_ssh_private_key_file=ansible.pem
|
||||
chromium_revision=1343869
|
||||
chromium_revision=1204232
|
||||
|
|
|
|||
|
|
@ -236,6 +236,12 @@
|
|||
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
|
||||
|
||||
- name: Creating Headless Chromium Configuration
|
||||
copy:
|
||||
content: |
|
||||
|
|
|
|||
BIN
bin/al2.tar.br
BIN
bin/al2.tar.br
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
bin/fonts.tar.br
BIN
bin/fonts.tar.br
Binary file not shown.
Binary file not shown.
|
|
@ -16,4 +16,4 @@
|
|||
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.
|
||||
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`](app.mjs) for more details.
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@
|
|||
"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.",
|
||||
"description": "AWS Lambda Function that loads Chromium",
|
||||
"main": "app.mjs",
|
||||
"devDependencies": {
|
||||
"@sparticuz/chromium": "^119.0.0"
|
||||
"@sparticuz/chromium": "^118.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"puppeteer-core": "^21.5.1"
|
||||
"puppeteer-core": "^21.4.0"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,6 @@
|
|||
"version": "1.0.0",
|
||||
"description": "Chromium layer for AWS Lambda",
|
||||
"dependencies": {
|
||||
"@sparticuz/chromium": "^119.0.0"
|
||||
"@sparticuz/chromium": "^118.0.0"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,40 +1,40 @@
|
|||
{
|
||||
"name": "@sparticuz/chromium",
|
||||
"version": "130.0.0",
|
||||
"version": "119.0.1-next.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@sparticuz/chromium",
|
||||
"version": "130.0.0",
|
||||
"version": "119.0.1-next.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.15.9",
|
||||
"tar-fs": "^3.0.6"
|
||||
"follow-redirects": "^1.15.3",
|
||||
"tar-fs": "^3.0.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tsconfig/node20": "^20.1.4",
|
||||
"@tsconfig/strictest": "^2.0.5",
|
||||
"@tsconfig/node16": "^16.1.1",
|
||||
"@tsconfig/strictest": "^2.0.2",
|
||||
"@types/follow-redirects": "^1.14.4",
|
||||
"@types/node": "^20.16.10",
|
||||
"@types/node": "^18.18.11",
|
||||
"@types/tar-fs": "^2.0.4",
|
||||
"clean-modules": "^3.1.1",
|
||||
"typescript": "^5.6.2"
|
||||
"clean-modules": "^3.0.4",
|
||||
"typescript": "^5.3.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==",
|
||||
"node_modules/@tsconfig/node16": {
|
||||
"version": "16.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-16.1.1.tgz",
|
||||
"integrity": "sha512-+pio93ejHN4nINX4pXqfnR/fPLRtJBaT4ORaa5RH0Oc1zoYmo2B2koG+M328CQhHKn1Wj6FcOxCDFXAot9NhvA==",
|
||||
"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==",
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@tsconfig/strictest/-/strictest-2.0.2.tgz",
|
||||
"integrity": "sha512-jt4jIsWKvUvuY6adJnQJlb/UR7DdjC8CjHI/OaSQruj2yX9/K6+KOvDt/vD6udqos/FUk5Op66CvYT7TBLYO5Q==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/follow-redirects": {
|
||||
|
|
@ -47,13 +47,12 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "20.16.10",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.16.10.tgz",
|
||||
"integrity": "sha512-vQUKgWTjEIRFCvK6CyriPH3MZYiYlNy0fKiEYHWbcoWLEgs4opurGGKlebrTLqdSMIbXImH6XExNiIyNUv3WpA==",
|
||||
"version": "18.18.11",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.18.11.tgz",
|
||||
"integrity": "sha512-c1vku6qnTeujJneYH94/4aq73XrVcsJe35UPyAsSok1ijiKrkRzK+AxQPSpNMUnC03roWBBwJx/9I8V7lQoxmA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"undici-types": "~6.19.2"
|
||||
"undici-types": "~5.26.4"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/tar-fs": {
|
||||
|
|
@ -80,45 +79,11 @@
|
|||
"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==",
|
||||
"version": "3.0.4",
|
||||
"resolved": "https://registry.npmjs.org/clean-modules/-/clean-modules-3.0.4.tgz",
|
||||
"integrity": "sha512-UtidYdwZScv7TEmPuNBU1IDh2UrLH9FNYnhKYterm3jTtOGtSOa02J5aKHvnauqS/TKqJGPpC4bmuRDAXk61EQ==",
|
||||
"dev": true,
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"clipanion": "^3.2.1",
|
||||
"picomatch": "^2.3.0",
|
||||
|
|
@ -159,16 +124,15 @@
|
|||
"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==",
|
||||
"version": "1.15.3",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz",
|
||||
"integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
"url": "https://github.com/sponsors/RubenVerborgh"
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=4.0"
|
||||
},
|
||||
|
|
@ -178,6 +142,11 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"node_modules/mkdirp-classic": {
|
||||
"version": "0.5.3",
|
||||
"resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz",
|
||||
"integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A=="
|
||||
},
|
||||
"node_modules/once": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||
|
|
@ -273,16 +242,13 @@
|
|||
}
|
||||
},
|
||||
"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==",
|
||||
"version": "3.0.4",
|
||||
"resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-3.0.4.tgz",
|
||||
"integrity": "sha512-5AFQU8b9qLfZCX9zp2duONhPmZv0hGYiBPJsyUdqMjzq/mqVpy/rEUSeHk1+YitmxugaptgBh5oDGU3VsAJq4w==",
|
||||
"dependencies": {
|
||||
"mkdirp-classic": "^0.5.2",
|
||||
"pump": "^3.0.0",
|
||||
"tar-stream": "^3.1.5"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"bare-fs": "^2.1.1",
|
||||
"bare-path": "^2.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/tar-stream": {
|
||||
|
|
@ -302,11 +268,10 @@
|
|||
"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==",
|
||||
"version": "5.3.2",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.2.tgz",
|
||||
"integrity": "sha512-6l+RyNy7oAHDfxC4FzSJcz9vnjTKxrLpDG5M2Vu4SHRVNg6xzqZp6LYSR9zjqQTu8DU/f5xwxUdADOkbrIX2gQ==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
"tsserver": "bin/tsserver"
|
||||
|
|
@ -316,11 +281,10 @@
|
|||
}
|
||||
},
|
||||
"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"
|
||||
"version": "5.26.5",
|
||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz",
|
||||
"integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/wrappy": {
|
||||
"version": "1.0.2",
|
||||
|
|
|
|||
16
package.json
16
package.json
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@sparticuz/chromium",
|
||||
"version": "130.0.0",
|
||||
"version": "119.0.1-next.0",
|
||||
"description": "Chromium Binary for Serverless Platforms",
|
||||
"keywords": [
|
||||
"aws",
|
||||
|
|
@ -36,17 +36,17 @@
|
|||
"test": "make clean && make && make pretest && make test"
|
||||
},
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.15.9",
|
||||
"tar-fs": "^3.0.6"
|
||||
"follow-redirects": "^1.15.3",
|
||||
"tar-fs": "^3.0.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tsconfig/node20": "^20.1.4",
|
||||
"@tsconfig/strictest": "^2.0.5",
|
||||
"@tsconfig/node16": "^16.1.1",
|
||||
"@tsconfig/strictest": "^2.0.2",
|
||||
"@types/follow-redirects": "^1.14.4",
|
||||
"@types/node": "^20.16.10",
|
||||
"@types/node": "^18.18.11",
|
||||
"@types/tar-fs": "^2.0.4",
|
||||
"clean-modules": "^3.1.1",
|
||||
"typescript": "^5.6.2"
|
||||
"clean-modules": "^3.0.4",
|
||||
"typescript": "^5.3.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 16"
|
||||
|
|
|
|||
|
|
@ -26,14 +26,12 @@ export const isValidUrl = (input: string) => {
|
|||
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")
|
||||
process.env["AWS_EXECUTION_ENV"].includes("AWS_Lambda_nodejs")
|
||||
) {
|
||||
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")
|
||||
process.env["AWS_LAMBDA_JS_RUNTIME"].includes("nodejs")
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -46,11 +44,6 @@ export const isRunningInAwsLambdaNode20 = () => {
|
|||
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;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -51,36 +51,18 @@ interface Viewport {
|
|||
|
||||
if (isRunningInAwsLambda()) {
|
||||
if (process.env["FONTCONFIG_PATH"] === undefined) {
|
||||
process.env["FONTCONFIG_PATH"] = "/tmp/fonts";
|
||||
process.env["FONTCONFIG_PATH"] = "/tmp/aws";
|
||||
}
|
||||
|
||||
if (process.env["LD_LIBRARY_PATH"] === undefined) {
|
||||
process.env["LD_LIBRARY_PATH"] = "/tmp/al2/lib";
|
||||
process.env["LD_LIBRARY_PATH"] = "/tmp/aws/lib";
|
||||
} else if (
|
||||
process.env["LD_LIBRARY_PATH"].startsWith("/tmp/al2/lib") !== true
|
||||
process.env["LD_LIBRARY_PATH"].startsWith("/tmp/aws/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",
|
||||
"/tmp/aws/lib",
|
||||
isRunningInAwsLambdaNode20() ? "/tmp/al2023/lib" : undefined,
|
||||
...process.env["LD_LIBRARY_PATH"].split(":"),
|
||||
]),
|
||||
].join(":");
|
||||
|
|
@ -93,7 +75,7 @@ class Chromium {
|
|||
* https://developer.chrome.com/articles/new-headless/#try-out-the-new-headless
|
||||
* @values true or "new"
|
||||
*/
|
||||
private static headlessMode: true | "shell" = "shell";
|
||||
private static headlessMode: true | "new" = "new";
|
||||
|
||||
/**
|
||||
* If true, the graphics stack and webgl is enabled,
|
||||
|
|
@ -223,7 +205,6 @@ class 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",
|
||||
|
|
@ -240,11 +221,9 @@ class 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");
|
||||
this.graphics
|
||||
? graphicsFlags.push("--use-gl=angle", "--use-angle=swiftshader")
|
||||
: graphicsFlags.push("--disable-webgl");
|
||||
|
||||
const insecureFlags = [
|
||||
"--allow-running-insecure-content", // https://source.chromium.org/search?q=lang:cpp+symbol:kAllowRunningInsecureContent&ss=chromium
|
||||
|
|
@ -256,7 +235,7 @@ class Chromium {
|
|||
];
|
||||
|
||||
const headlessFlags = [
|
||||
this.headless === "shell" ? "--headless='shell'" : "--headless",
|
||||
this.headless === "new" ? "--headless='new'" : "--headless",
|
||||
];
|
||||
|
||||
return [
|
||||
|
|
@ -327,20 +306,17 @@ class Chromium {
|
|||
}
|
||||
|
||||
// Extract the required files
|
||||
const promises = [
|
||||
LambdaFS.inflate(`${input}/chromium.br`),
|
||||
LambdaFS.inflate(`${input}/fonts.tar.br`),
|
||||
];
|
||||
const promises = [LambdaFS.inflate(`${input}/chromium.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`));
|
||||
promises.push(LambdaFS.inflate(`${input}/aws.tar.br`));
|
||||
if (isRunningInAwsLambdaNode20()) {
|
||||
promises.push(LambdaFS.inflate(`${input}/al2023.tar.br`));
|
||||
}
|
||||
}
|
||||
|
||||
// Await all extractions
|
||||
|
|
@ -351,10 +327,10 @@ class Chromium {
|
|||
|
||||
/**
|
||||
* Returns the headless mode.
|
||||
* "shell" means the 'old' (legacy, chromium < 112) headless mode.
|
||||
* `true` means the 'new' headless mode.
|
||||
* `true` means the 'old' (legacy, chromium < 112) headless mode.
|
||||
* "new" means the 'new' headless mode.
|
||||
* https://developer.chrome.com/articles/new-headless/#try-out-the-new-headless
|
||||
* @returns true | "shell"
|
||||
* @returns true | "new"
|
||||
*/
|
||||
public static get headless() {
|
||||
return this.headlessMode;
|
||||
|
|
@ -362,18 +338,18 @@ class Chromium {
|
|||
|
||||
/**
|
||||
* Sets the headless mode.
|
||||
* "shell" means the 'old' (legacy, chromium < 112) headless mode.
|
||||
* `true` means the 'new' headless mode.
|
||||
* `true` means the 'old' (legacy, chromium < 112) headless mode.
|
||||
* "new" means the 'new' headless mode.
|
||||
* https://developer.chrome.com/articles/new-headless/#try-out-the-new-headless
|
||||
* @default "shell"
|
||||
* @default "new"
|
||||
*/
|
||||
public static set setHeadlessMode(value: true | "shell") {
|
||||
public static set setHeadlessMode(value: true | "new") {
|
||||
if (
|
||||
(typeof value === "string" && value !== "shell") ||
|
||||
(typeof value === "string" && value !== "new") ||
|
||||
(typeof value === "boolean" && value !== true)
|
||||
) {
|
||||
throw new Error(
|
||||
`Headless mode must be either \`true\` or 'shell', you entered '${value}'`
|
||||
`Headless mode must be either \`true\` or 'new', you entered '${value}'`
|
||||
);
|
||||
}
|
||||
this.headlessMode = value;
|
||||
|
|
@ -400,11 +376,7 @@ class Chromium {
|
|||
`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;
|
||||
this.graphicsMode = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -72,4 +72,4 @@ class LambdaFS {
|
|||
}
|
||||
}
|
||||
|
||||
export default LambdaFS;
|
||||
export = LambdaFS;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
{
|
||||
"extends": ["@tsconfig/node20/tsconfig", "@tsconfig/strictest"],
|
||||
"extends": ["@tsconfig/node16/tsconfig", "@tsconfig/strictest"],
|
||||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"lib": ["dom", "ES2023"],
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"lib": ["dom", "ES2021"],
|
||||
"module": "Node16",
|
||||
"moduleResolution": "Node16",
|
||||
"outDir": "build"
|
||||
},
|
||||
"include": ["source"]
|
||||
|
|
|
|||
Loading…
Reference in New Issue