Skip to content

Commit 9ee70ad

Browse files
authored
Merge pull request #11887 from quarto-dev/check/chromium
2 parents c504fc8 + 4c794f1 commit 9ee70ad

File tree

3 files changed

+63
-7
lines changed

3 files changed

+63
-7
lines changed

news/changelog-1.7.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,4 @@ All changes included in 1.7:
6868
- ([#11643](https://github.com/quarto-dev/quarto-cli/issues/11643)): Improve highlighting of nested code block inside markdown code block, i.e. using ` ```{{python}} ` or ` ```python ` inside ` ````markdown` fenced code block.
6969
- ([fb38eb5](https://github.com/quarto-dev/quarto-cli/commit/fb38eb56c11e09f44cef58fd3b697ff24bb5a3f3)) Use the `latest` parser for Acorn when analyzing JS code imported from OJS blocks.
7070
- ([#10532](https://github.com/quarto-dev/quarto-cli/issues/10532)): Quarto changed default of `--headless=old` to `--headless` as [Chrome 132 has removed old headless mode](https://developer.chrome.com/blog/removing-headless-old-from-chrome) and only support new mode. For using old mode, `QUARTO_CHROMIUM` could be set to a [new `chrome-headless-shell` binary](https://developer.chrome.com/blog/chrome-headless-shell) or too an older chrome version (between 128 and 132) and `QUARTO_CHROMIUM_HEADLESS_MODE` set to `old` for using old headless mode with that compatabitle version.
71+
- ([#10961](https://github.com/quarto-dev/quarto-cli/issues/10961)): Add more information on which Chrome Headless will be used in `quarto check install`. This is helpful to help debug mermaid issues.

src/command/check/check.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import { typstBinaryPath } from "../../core/typst.ts";
4848
import { quartoCacheDir } from "../../core/appdirs.ts";
4949
import { isWindows } from "../../deno_ral/platform.ts";
5050
import { makeStringEnumTypeEnforcer } from "../../typing/dynamic.ts";
51+
import { findChrome } from "../../core/puppeteer.ts";
5152

5253
export const kTargets = [
5354
"install",
@@ -212,11 +213,12 @@ async function checkInstall(services: RenderServices) {
212213
info("");
213214
const toolsMessage = "Checking tools....................";
214215
const toolsOutput: string[] = [];
216+
let tools: Awaited<ReturnType<typeof allTools>>;
215217
await withSpinner({
216218
message: toolsMessage,
217219
doneMessage: toolsMessage + "OK",
218220
}, async () => {
219-
const tools = await allTools();
221+
tools = await allTools();
220222

221223
for (const tool of tools.installed) {
222224
const version = await tool.installedVersion() || "(external install)";
@@ -260,6 +262,43 @@ async function checkInstall(services: RenderServices) {
260262
latexOutput.forEach((out) => info(out));
261263
info("");
262264

265+
const chromeHeadlessMessage = "Checking Chrome Headless....................";
266+
const chromeHeadlessOutput: string[] = [];
267+
await withSpinner({
268+
message: chromeHeadlessMessage,
269+
doneMessage: chromeHeadlessMessage + "OK",
270+
}, async () => {
271+
const chromeDetected = await findChrome();
272+
const chromiumQuarto = tools.installed.find((tool) =>
273+
tool.name === "chromium"
274+
);
275+
if (chromeDetected.path !== undefined) {
276+
chromeHeadlessOutput.push(`${kIndent}Using: Chrome found on system`);
277+
chromeHeadlessOutput.push(
278+
`${kIndent}Path: ${chromeDetected.path}`,
279+
);
280+
if (chromeDetected.source) {
281+
chromeHeadlessOutput.push(`${kIndent}Source: ${chromeDetected.source}`);
282+
}
283+
} else if (chromiumQuarto !== undefined) {
284+
chromeHeadlessOutput.push(
285+
`${kIndent}Using: Chromium installed by Quarto`,
286+
);
287+
if (chromiumQuarto?.binDir) {
288+
chromeHeadlessOutput.push(
289+
`${kIndent}Path: ${chromiumQuarto?.binDir}`,
290+
);
291+
}
292+
chromeHeadlessOutput.push(
293+
`${kIndent}Version: ${chromiumQuarto.installedVersion}`,
294+
);
295+
} else {
296+
chromeHeadlessOutput.push(`${kIndent}Chrome: (not detected)`);
297+
}
298+
});
299+
chromeHeadlessOutput.forEach((out) => info(out));
300+
info("");
301+
263302
const kMessage = "Checking basic markdown render....";
264303
await withSpinner({
265304
message: kMessage,

src/core/puppeteer.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,21 @@ export async function withHeadlessBrowser<T>(
200200
}
201201
}
202202

203-
async function findChrome(): Promise<string | undefined> {
203+
interface ChromeInfo {
204+
path: string | undefined;
205+
source: string | undefined;
206+
}
207+
208+
export async function findChrome(): Promise<ChromeInfo> {
204209
let path;
210+
let source;
205211
// First check env var and use this path if specified
206212
const envPath = Deno.env.get("QUARTO_CHROMIUM");
207213
if (envPath) {
208214
debug("[CHROMIUM] Using path specified in QUARTO_CHROMIUM");
209215
if (safeExistsSync(envPath)) {
210216
debug(`[CHROMIUM] Found at ${envPath}, and will be used.`);
211-
return envPath;
217+
return { path: envPath, source: "QUARTO_CHROMIUM" };
212218
} else {
213219
debug(
214220
`[CHROMIUM] Not found at ${envPath}. Check your environment variable valye. Searching now for another binary.`,
@@ -222,6 +228,7 @@ async function findChrome(): Promise<string | undefined> {
222228
"/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
223229
];
224230
path = programs.find(safeExistsSync);
231+
source = "MacOS known location";
225232
} else if (isWindows) {
226233
// Try the HKLM key
227234
const programs = ["chrome.exe", "msedge.exe"];
@@ -231,7 +238,10 @@ async function findChrome(): Promise<string | undefined> {
231238
programs[i],
232239
"(Default)",
233240
);
234-
if (path && safeExistsSync(path)) break;
241+
if (path && safeExistsSync(path)) {
242+
source = "Windows Registry";
243+
break;
244+
}
235245
}
236246

237247
// Try the HKCR key
@@ -244,7 +254,10 @@ async function findChrome(): Promise<string | undefined> {
244254
);
245255
path = path?.match(/"(.*)"/);
246256
path = path ? path[1] : undefined;
247-
if (path && existsSync(path)) break;
257+
if (path && existsSync(path)) {
258+
source = "Windows Registry";
259+
break;
260+
}
248261
}
249262
}
250263
} else {
@@ -254,14 +267,17 @@ async function findChrome(): Promise<string | undefined> {
254267
if (!path) {
255268
path = await which("chromium-browser");
256269
}
270+
if (path && existsSync(path)) {
271+
source = "PATH";
272+
}
257273
}
258274
if (path) {
259275
debug("[CHROMIUM] Found Chromium on OS known location");
260276
debug(`[CHROMIUM] Path: ${path}`);
261277
} else {
262278
debug("[CHROMIUM] Chromium not found on OS known location");
263279
}
264-
return path;
280+
return { path: path, source: source };
265281
}
266282

267283
export async function getBrowserExecutablePath() {
@@ -272,7 +288,7 @@ export async function getBrowserExecutablePath() {
272288
let executablePath: string | undefined = undefined;
273289

274290
if (executablePath === undefined) {
275-
executablePath = await findChrome();
291+
executablePath = (await findChrome()).path;
276292
}
277293

278294
if (executablePath === undefined && availableRevisions.length > 0) {

0 commit comments

Comments
 (0)