Merge pull request #233 from Sparticuz/chromium122

This commit is contained in:
Kyle McNally 2024-02-22 12:11:51 -05:00 committed by GitHub
commit 1da7ed4b19
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 75 additions and 48 deletions

View File

@ -14,7 +14,7 @@ test:
npm install --fund=false --package-lock=false
npm run build
mkdir -p nodejs
npm install --prefix nodejs/ tar-fs@3.0.4 follow-redirects@1.15.5 --bin-links=false --fund=false --omit=optional --omit=dev --package-lock=false --save=false
npm install --prefix nodejs/ tar-fs@3.0.5 follow-redirects@1.15.5 --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

View File

@ -50,7 +50,9 @@ const test = require("node:test");
const puppeteer = require("puppeteer-core");
const chromium = require("@sparticuz/chromium");
// Optional: If you'd like to use the legacy headless mode. "new" is the default.
// Optional: If you'd like to use the new headless mode. "chrome-headless-shell" is the default.
// NOTE: Because we build the chrome-headless-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.
@ -163,7 +165,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.
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
@ -258,8 +260,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 `"new"` |
| `headless` | `true \| "new"` | Returns `true` or `"new"` depending on what version of chrome's headless you are running |
| `setHeadlessMode` | `void` | Sets the headless mode to either `true` or `"chrome-headless-shell"` |
| `headless` | `true \| "chrome-headless-shell"` | Returns `true` or `"chrome-headless-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 |

View File

@ -3,21 +3,14 @@
"url": "https://example.com",
"expected": {
"title": "Example Domain",
"screenshot": "3f1863ac017614ce6a389cf719da28b774595abe"
}
},
{
"url": "https://example.com",
"expected": {
"title": "Example Domain",
"screenshot": "3f1863ac017614ce6a389cf719da28b774595abe"
"screenshot": "835f3ccc8fdbcb3a4a067666f1e9648e9e513570"
}
},
{
"url": "https://get.webgl.org",
"expected": {
"remove": "logo-container",
"screenshot": "bf35ed6405670c506b549906f6b467421bc8b430"
"screenshot": "7b4110af7294ae55452d636dd8e900574b21ea2d"
}
}
]

View File

@ -21,7 +21,7 @@ exports.handler = async (event, context) => {
const contexts = [browser.defaultBrowserContext()];
while (contexts.length < event.length) {
contexts.push(await browser.createIncognitoBrowserContext());
contexts.push(await browser.createBrowserContext());
}
for (let context of contexts) {

View File

@ -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=1233107
chromium_revision=1250580

BIN
bin/chromium.br Executable file → Normal file

Binary file not shown.

Binary file not shown.

67
package-lock.json generated
View File

@ -10,13 +10,13 @@
"license": "MIT",
"dependencies": {
"follow-redirects": "^1.15.5",
"tar-fs": "^3.0.4"
"tar-fs": "^3.0.5"
},
"devDependencies": {
"@tsconfig/node16": "^16.1.1",
"@tsconfig/strictest": "^2.0.2",
"@tsconfig/strictest": "^2.0.3",
"@types/follow-redirects": "^1.14.4",
"@types/node": "^20.11.10",
"@types/node": "^20.11.19",
"@types/tar-fs": "^2.0.4",
"clean-modules": "^3.0.4",
"typescript": "^5.3.3"
@ -32,9 +32,9 @@
"dev": true
},
"node_modules/@tsconfig/strictest": {
"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==",
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/@tsconfig/strictest/-/strictest-2.0.3.tgz",
"integrity": "sha512-MroLvRhMbqtXI5WBSwoomro6OQS4xnCoudUrMb20JO0vLKUs0bAaCEcvM/immEBSJjFAK1l6jW1oAO8q3Ancrg==",
"dev": true
},
"node_modules/@types/follow-redirects": {
@ -47,9 +47,9 @@
}
},
"node_modules/@types/node": {
"version": "20.11.10",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.10.tgz",
"integrity": "sha512-rZEfe/hJSGYmdfX9tvcPMYeYPW2sNl50nsw4jZmRcaG0HIAb0WYEpsB05GOb53vjqpyE9GUhlDQ4jLSoB5q9kg==",
"version": "20.11.19",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.19.tgz",
"integrity": "sha512-7xMnVEcZFu0DikYjWOlRq7NTPETrm7teqUT2WkQjrTIkEgUyyGdWsj/Zg8bEJt5TNklzbPD1X3fqfsHw3SpapQ==",
"dev": true,
"dependencies": {
"undici-types": "~5.26.4"
@ -79,6 +79,39 @@
"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.0.4",
"resolved": "https://registry.npmjs.org/clean-modules/-/clean-modules-3.0.4.tgz",
@ -142,11 +175,6 @@
}
}
},
"node_modules/mkdirp-classic": {
"version": "0.5.3",
"resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz",
"integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A=="
},
"node_modules/once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
@ -242,13 +270,16 @@
}
},
"node_modules/tar-fs": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-3.0.4.tgz",
"integrity": "sha512-5AFQU8b9qLfZCX9zp2duONhPmZv0hGYiBPJsyUdqMjzq/mqVpy/rEUSeHk1+YitmxugaptgBh5oDGU3VsAJq4w==",
"version": "3.0.5",
"resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-3.0.5.tgz",
"integrity": "sha512-JOgGAmZyMgbqpLwct7ZV8VzkEB6pxXFBVErLtb+XCOqzc6w1xiWKI9GVd6bwk68EX7eJ4DWmfXVmq8K2ziZTGg==",
"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": {

View File

@ -37,13 +37,13 @@
},
"dependencies": {
"follow-redirects": "^1.15.5",
"tar-fs": "^3.0.4"
"tar-fs": "^3.0.5"
},
"devDependencies": {
"@tsconfig/node16": "^16.1.1",
"@tsconfig/strictest": "^2.0.2",
"@tsconfig/strictest": "^2.0.3",
"@types/follow-redirects": "^1.14.4",
"@types/node": "^20.11.10",
"@types/node": "^20.11.19",
"@types/tar-fs": "^2.0.4",
"clean-modules": "^3.0.4",
"typescript": "^5.3.3"

View File

@ -93,7 +93,7 @@ class Chromium {
* https://developer.chrome.com/articles/new-headless/#try-out-the-new-headless
* @values true or "new"
*/
private static headlessMode: true | "new" = "new";
private static headlessMode: true | "chrome-headless-shell" = "chrome-headless-shell";
/**
* If true, the graphics stack and webgl is enabled,
@ -223,6 +223,7 @@ 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",
@ -253,7 +254,7 @@ class Chromium {
];
const headlessFlags = [
this.headless === "new" ? "--headless='new'" : "--headless",
this.headless === "chrome-headless-shell" ? "--headless='chrome-headless-shell'" : "--headless",
];
return [
@ -348,10 +349,10 @@ class Chromium {
/**
* Returns the headless mode.
* `true` means the 'old' (legacy, chromium < 112) headless mode.
* "new" means the 'new' headless mode.
* "chrome-headless-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 | "new"
* @returns true | "chrome-headless-shell"
*/
public static get headless() {
return this.headlessMode;
@ -359,18 +360,18 @@ class Chromium {
/**
* Sets the headless mode.
* `true` means the 'old' (legacy, chromium < 112) headless mode.
* "new" means the 'new' headless mode.
* "chrome-headless-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 "new"
* @default "chrome-headless-shell"
*/
public static set setHeadlessMode(value: true | "new") {
public static set setHeadlessMode(value: true | "chrome-headless-shell") {
if (
(typeof value === "string" && value !== "new") ||
(typeof value === "string" && value !== "chrome-headless-shell") ||
(typeof value === "boolean" && value !== true)
) {
throw new Error(
`Headless mode must be either \`true\` or 'new', you entered '${value}'`
`Headless mode must be either \`true\` or 'chrome-headless-shell', you entered '${value}'`
);
}
this.headlessMode = value;