Fix types

This commit is contained in:
Kyle McNally 2024-03-20 14:23:39 -04:00
parent c640690f16
commit ce553320d8
2 changed files with 13 additions and 13 deletions

View File

@ -50,8 +50,8 @@ const test = require("node:test");
const puppeteer = require("puppeteer-core"); const puppeteer = require("puppeteer-core");
const chromium = require("@sparticuz/chromium"); const chromium = require("@sparticuz/chromium");
// Optional: If you'd like to use the new headless mode. "chrome-headless-shell" is the default. // Optional: If you'd like to use the new headless mode. "shell" is the default.
// NOTE: Because we build the chrome-headless-shell binary, this option does not work. // 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. // However, this option will stay so when we migrate to full chromium it will work.
chromium.setHeadlessMode = true; chromium.setHeadlessMode = true;
@ -260,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). | | `args` | `Array<string>` | Provides a list of recommended additional [Chromium flags](https://github.com/GoogleChrome/chrome-launcher/blob/master/docs/chrome-flags-for-tools.md). |
| `defaultViewport` | `Object` | Returns a sensible default viewport for serverless. | | `defaultViewport` | `Object` | Returns a sensible default viewport for serverless. |
| `executablePath(location?: string)` | `Promise<string>` | Returns the path the Chromium binary was extracted to. | | `executablePath(location?: string)` | `Promise<string>` | Returns the path the Chromium binary was extracted to. |
| `setHeadlessMode` | `void` | Sets the headless mode to either `true` or `"chrome-headless-shell"` | | `setHeadlessMode` | `void` | Sets the headless mode to either `true` or `"shell"` |
| `headless` | `true \| "chrome-headless-shell"` | Returns `true` or `"chrome-headless-shell"` depending on what version of chrome's headless you are running | | `headless` | `true \| "shell"` | Returns `true` or `"shell"` depending on what version of chrome's headless you are running |
| `setGraphicsMode` | `void` | Sets the graphics mode to either `true` or `false` | | `setGraphicsMode` | `void` | Sets the graphics mode to either `true` or `false` |
| `graphics` | `boolean` | Returns a boolean depending on whether webgl is enabled or disabled | | `graphics` | `boolean` | Returns a boolean depending on whether webgl is enabled or disabled |

View File

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