@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.
- package/chrome.mjs +16 -7
- package/package.json +1 -1
package/chrome.mjs
CHANGED
|
@@ -49,22 +49,31 @@ function playwrightChromes() {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
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
|
|
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, [
|
|
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;
|