@zaisma/cli 0.39.0 → 0.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/chrome.mjs +16 -7
  2. package/package.json +1 -1
package/chrome.mjs CHANGED
@@ -49,22 +49,31 @@ function playwrightChromes() {
49
49
  }
50
50
 
51
51
  /**
52
- * Headless Chrome at path with WebGL in software (SwiftShader, as on Zaisma's check and on machines without a GPU), or on the machine's
53
- * own GPU with isGpu (scripts/city.mjs times and renders the city on it), or with no GPU and no WebGL at all with isDrawingOnCpu (the
54
- * layout check measures boxes, not pixels), and a DevTools connection to it: send(method, parameters,
55
- * sessionId), listen(sessionId, onEvent) and close().
52
+ * What Chrome starts with besides its profile. It never touches the machine's GPU: WebGL in software (SwiftShader, as on Zaisma's check and
53
+ * on machines without a GPU), or with isDrawingOnCpu --disable-gpu, for the layout check, which measures boxes, not pixels (no WebGL on a Mac, SwiftShader on Linux).
54
+ * test/node/chrome-no-gpu.test.ts holds this, and that nothing else starts a Chrome.
56
55
  */
57
- export async function openChrome(path, profilePrefix, { isGpu = false, isDrawingOnCpu = false } = {}) {
56
+ export function chromeFlags({ isDrawingOnCpu = false } = {}) {
57
+ const drawing = isDrawingOnCpu ? ["--disable-gpu"] : ["--use-angle=swiftshader", "--enable-unsafe-swiftshader"];
58
+ return ["--headless=new", "--remote-debugging-port=0", "--no-first-run", "--no-default-browser-check", ...drawing, "--autoplay-policy=no-user-gesture-required", "--hide-scrollbars", "--disable-renderer-backgrounding", "--disable-background-timer-throttling", "--disable-backgrounding-occluded-windows"];
59
+ }
60
+
61
+ /**
62
+ * Headless Chrome at path, without the machine's GPU (chromeFlags), and a DevTools connection to it: send(method, parameters, sessionId),
63
+ * listen(sessionId, onEvent) and close().
64
+ */
65
+ export async function openChrome(path, profilePrefix, { isDrawingOnCpu = false, ...others } = {}) {
66
+ const unknownOptions = Object.keys(others);
67
+ if (unknownOptions.length) throw new Error(`openChrome has no option ${unknownOptions.join(", ")}: its only option is isDrawingOnCpu, and every Chrome runs without the machine's GPU.`);
58
68
  await sweepOrphans();
59
69
  // A folder for each Chrome: OWNER_FILE, which says whose it is, and Chrome's profile inside, removed before the folder so a profile
60
70
  // that can't be removed yet keeps its owner for the next sweep.
61
71
  const folder = mkdtempSync(join(tmpdir(), profilePrefix));
62
72
  const profile = join(folder, "profile");
63
73
  mkdirSync(profile);
64
- const webgl = isDrawingOnCpu ? ["--disable-gpu"] : isGpu ? ["--enable-gpu", "--ignore-gpu-blocklist", ...(process.platform === "darwin" ? ["--use-angle=metal"] : [])] : ["--use-angle=swiftshader", "--enable-unsafe-swiftshader"];
65
74
  let child;
66
75
  try {
67
- child = spawn(path, ["--headless=new", "--remote-debugging-port=0", `--user-data-dir=${profile}`, "--no-first-run", "--no-default-browser-check", ...webgl, "--autoplay-policy=no-user-gesture-required", "--hide-scrollbars", "--disable-renderer-backgrounding", "--disable-background-timer-throttling", "--disable-backgrounding-occluded-windows", "about:blank"], { stdio: ["ignore", "ignore", "pipe"] });
76
+ child = spawn(path, [...chromeFlags({ isDrawingOnCpu }), `--user-data-dir=${profile}`, "about:blank"], { stdio: ["ignore", "ignore", "pipe"] });
68
77
  } catch (error) {
69
78
  rmSync(folder, { recursive: true, force: true });
70
79
  throw error;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zaisma/cli",
3
- "version": "0.39.0",
3
+ "version": "0.40.0",
4
4
  "description": "Upload and publish browser games on Zaisma from the command line.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://zaisma.com",