Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chromium 122 #233

Merged
merged 6 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 |

Expand Down
11 changes: 2 additions & 9 deletions _/amazon/events/example.com.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
]
2 changes: 1 addition & 1 deletion _/amazon/handlers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion _/ansible/inventory.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Binary file modified bin/chromium.br
100755 → 100644
Binary file not shown.
Binary file modified bin/swiftshader.tar.br
Binary file not shown.
67 changes: 49 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
23 changes: 12 additions & 11 deletions source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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 [
Expand Down Expand Up @@ -348,29 +349,29 @@ 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;
}

/**
* 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;
Expand Down