Skip to content

Commit 038fa2a

Browse files
committed
Add information on which chrome is found and used in quarto check
1 parent 11c6705 commit 038fa2a

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

src/command/check/check.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,24 +268,29 @@ async function checkInstall(services: RenderServices) {
268268
message: chromeHeadlessMessage,
269269
doneMessage: chromeHeadlessMessage + "OK",
270270
}, async () => {
271-
const chromeSystemPath = await findChrome();
272-
const chromiumQuartoPath = tools.installed.find((tool) =>
271+
const chromeDetected = await findChrome();
272+
const chromiumQuarto = tools.installed.find((tool) =>
273273
tool.name === "chromium"
274274
);
275-
if (chromeSystemPath !== undefined) {
275+
if (chromeDetected.path !== undefined) {
276276
chromeHeadlessOutput.push(`${kIndent}Using: Chrome found on system`);
277-
chromeHeadlessOutput.push(`${kIndent}Path: ${dirname(chromeSystemPath)}`);
278-
} else if (chromiumQuartoPath) {
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) {
279284
chromeHeadlessOutput.push(
280285
`${kIndent}Using: Chromium installed by Quarto`,
281286
);
282-
if (chromiumQuartoPath?.binDir) {
287+
if (chromiumQuarto?.binDir) {
283288
chromeHeadlessOutput.push(
284-
`${kIndent}Path: ${chromiumQuartoPath?.binDir}`,
289+
`${kIndent}Path: ${chromiumQuarto?.binDir}`,
285290
);
286291
}
287292
chromeHeadlessOutput.push(
288-
`${kIndent}Version: ${chromiumQuartoPath.installedVersion}`,
293+
`${kIndent}Version: ${chromiumQuarto.installedVersion}`,
289294
);
290295
} else {
291296
chromeHeadlessOutput.push(`${kIndent}Chrome: (not detected)`);

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-
export 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 @@ export 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 @@ export 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 @@ export 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 @@ export 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)