Skip to content

Commit 620cf87

Browse files
cdervclaude
andcommitted
Wire chrome-headless-shell into tool registry, browser discovery, and quarto check
- Register chrome-headless-shell in kInstallableTools, enabling `quarto install/uninstall chrome-headless-shell` - Fix installableTools() to return registry keys instead of lowercased display names (broken for multi-word tool names) - Add WSL handling: allow chrome-headless-shell install with info note (unlike full chromium which blocks on WSL) - Insert chrome-headless-shell as priority 2 in getBrowserExecutablePath() between system Chrome and legacy puppeteer revisions - Update error message to recommend chrome-headless-shell over chromium - Add chrome-headless-shell detection in `quarto check install` - Fix pre-existing bug: chromium lookup in quarto check used display name comparison that never matched due to casing; now uses registry key lookup Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b3da471 commit 620cf87

4 files changed

Lines changed: 57 additions & 11 deletions

File tree

‎src/command/check/check.ts‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { pandocBinaryPath } from "../../core/resources.ts";
2222
import { lines } from "../../core/text.ts";
2323
import { satisfies } from "semver/mod.ts";
2424
import { dartCommand } from "../../core/dart-sass.ts";
25-
import { allTools } from "../../tools/tools.ts";
25+
import { allTools, installableTool } from "../../tools/tools.ts";
2626
import { texLiveContext, tlVersion } from "../render/latexmk/texlive.ts";
2727
import { which } from "../../core/path.ts";
2828
import { dirname } from "../../deno_ral/path.ts";
@@ -32,6 +32,11 @@ import { quartoCacheDir } from "../../core/appdirs.ts";
3232
import { isWindows } from "../../deno_ral/platform.ts";
3333
import { makeStringEnumTypeEnforcer } from "../../typing/dynamic.ts";
3434
import { findChrome } from "../../core/puppeteer.ts";
35+
import {
36+
chromeHeadlessShellExecutablePath,
37+
chromeHeadlessShellInstallDir,
38+
readInstalledVersion,
39+
} from "../../tools/impl/chrome-headless-shell.ts";
3540
import { executionEngines } from "../../execute/engine.ts";
3641

3742
export function getTargets(): readonly string[] {
@@ -437,9 +442,11 @@ async function checkInstall(conf: CheckConfiguration) {
437442
}
438443
const chromeCb = async () => {
439444
const chromeDetected = await findChrome();
440-
const chromiumQuarto = tools.installed.find((tool) =>
441-
tool.name === "chromium"
442-
);
445+
const chromeHsPath = chromeHeadlessShellExecutablePath();
446+
const chromiumTool = installableTool("chromium");
447+
const chromiumQuarto = chromiumTool && await chromiumTool.installed()
448+
? chromiumTool
449+
: undefined;
443450
if (chromeDetected.path !== undefined) {
444451
chromeHeadlessOutput.push(`${kIndent}Using: Chrome found on system`);
445452
chromeHeadlessOutput.push(
@@ -450,6 +457,18 @@ async function checkInstall(conf: CheckConfiguration) {
450457
}
451458
chromeJson["path"] = chromeDetected.path;
452459
chromeJson["source"] = chromeDetected.source;
460+
} else if (chromeHsPath !== undefined) {
461+
const version = readInstalledVersion(chromeHeadlessShellInstallDir());
462+
chromeJson["source"] = "quarto-chrome-headless-shell";
463+
chromeHeadlessOutput.push(
464+
`${kIndent}Using: Chrome Headless Shell installed by Quarto`,
465+
);
466+
chromeHeadlessOutput.push(`${kIndent}Path: ${chromeHsPath}`);
467+
chromeJson["path"] = chromeHsPath;
468+
if (version) {
469+
chromeHeadlessOutput.push(`${kIndent}Version: ${version}`);
470+
chromeJson["version"] = version;
471+
}
453472
} else if (chromiumQuarto !== undefined) {
454473
chromeJson["source"] = "quarto";
455474
chromeHeadlessOutput.push(

‎src/core/puppeteer.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { UnreachableError } from "./lib/error.ts";
1212
import { quartoDataDir } from "./appdirs.ts";
1313
import { isMac, isWindows } from "../deno_ral/platform.ts";
1414
import puppeteer from "puppeteer";
15+
import { chromeHeadlessShellExecutablePath } from "../tools/impl/chrome-headless-shell.ts";
1516

1617
// deno-lint-ignore no-explicit-any
1718
// let puppeteerImport: any = undefined;
@@ -291,10 +292,17 @@ export async function getBrowserExecutablePath() {
291292

292293
let executablePath: string | undefined = undefined;
293294

295+
// Priority 1: QUARTO_CHROMIUM env var + system Chrome/Edge
294296
if (executablePath === undefined) {
295297
executablePath = (await findChrome()).path;
296298
}
297299

300+
// Priority 2: Quarto-installed chrome-headless-shell
301+
if (executablePath === undefined) {
302+
executablePath = chromeHeadlessShellExecutablePath();
303+
}
304+
305+
// Priority 3: Legacy puppeteer-managed Chromium revisions
298306
if (executablePath === undefined && availableRevisions.length > 0) {
299307
// get the latest available revision
300308
availableRevisions.sort((a: string, b: string) => Number(b) - Number(a));
@@ -306,7 +314,7 @@ export async function getBrowserExecutablePath() {
306314
if (executablePath === undefined) {
307315
error("Chrome not found");
308316
info(
309-
"\nNo Chrome or Chromium installation was detected.\n\nPlease run 'quarto install chromium' to install Chromium.\n",
317+
"\nNo Chrome or Chromium installation was detected.\n\nPlease run 'quarto install chrome-headless-shell' to install a headless browser.\n",
310318
);
311319
throw new Error();
312320
}

‎src/tools/tools.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
} from "./types.ts";
1919
import { tinyTexInstallable } from "./impl/tinytex.ts";
2020
import { chromiumInstallable } from "./impl/chromium.ts";
21+
import { chromeHeadlessShellInstallable } from "./impl/chrome-headless-shell.ts";
2122
import { verapdfInstallable } from "./impl/verapdf.ts";
2223
import { downloadWithProgress } from "../core/download.ts";
2324
import { Confirm } from "cliffy/prompt/mod.ts";
@@ -32,6 +33,7 @@ const kInstallableTools: { [key: string]: InstallableTool } = {
3233
tinytex: tinyTexInstallable,
3334
// temporarily disabled until deno 1.28.* gets puppeteer support
3435
chromium: chromiumInstallable,
36+
"chrome-headless-shell": chromeHeadlessShellInstallable,
3537
verapdf: verapdfInstallable,
3638
};
3739

@@ -59,12 +61,7 @@ export async function allTools(): Promise<{
5961
}
6062

6163
export function installableTools(): string[] {
62-
const tools: string[] = [];
63-
Object.keys(kInstallableTools).forEach((key) => {
64-
const tool = kInstallableTools[key];
65-
tools.push(tool.name.toLowerCase());
66-
});
67-
return tools;
64+
return Object.keys(kInstallableTools);
6865
}
6966

7067
export async function printToolInfo(name: string) {
@@ -101,6 +98,11 @@ export function checkToolRequirement(name: string) {
10198
"- See https://github.com/quarto-dev/quarto-cli/issues/1822 for more context.",
10299
].join("\n"));
103100
return false;
101+
} else if (name.toLowerCase() === "chrome-headless-shell" && isWSL()) {
102+
info(
103+
"Note: chrome-headless-shell is a headless-only binary and should work on WSL without additional system dependencies.",
104+
);
105+
return true;
104106
} else {
105107
return true;
106108
}

‎tests/unit/tools/chrome-headless-shell.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { isWindows } from "../../../src/deno_ral/platform.ts";
1212
import { runningInCI } from "../../../src/core/ci-info.ts";
1313
import { InstallContext } from "../../../src/tools/types.ts";
1414
import { findCftExecutable } from "../../../src/tools/impl/chrome-for-testing.ts";
15+
import { installableTool, installableTools } from "../../../src/tools/tools.ts";
1516
import {
1617
chromeHeadlessShellInstallable,
1718
chromeHeadlessShellInstallDir,
@@ -238,3 +239,19 @@ unitTest("install lifecycle - prepare, install, verify, uninstall", async () =>
238239
safeRemoveSync(tempDir, { recursive: true });
239240
}
240241
}, { ignore: runningInCI() });
242+
243+
// -- Step 8: Tool registry integration --
244+
245+
unitTest("tool registry - chrome-headless-shell is listed in installableTools", async () => {
246+
const tools = installableTools();
247+
assert(
248+
tools.includes("chrome-headless-shell"),
249+
`installableTools() should include "chrome-headless-shell", got: ${tools}`,
250+
);
251+
});
252+
253+
unitTest("tool registry - installableTool looks up chrome-headless-shell", async () => {
254+
const tool = installableTool("chrome-headless-shell");
255+
assert(tool !== undefined, "installableTool should find chrome-headless-shell");
256+
assertEquals(tool.name, "Chrome Headless Shell");
257+
});

0 commit comments

Comments
 (0)