Skip to content

Commit c100f3c

Browse files
committed
Change priority order for chromium to use
- Env var - chrome-headless-shell - system - chromium
1 parent cd52e21 commit c100f3c

2 files changed

Lines changed: 38 additions & 29 deletions

File tree

src/command/check/check.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ 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 { safeExistsSync } from "../../core/path.ts";
3536
import {
3637
chromeHeadlessShellExecutablePath,
3738
chromeHeadlessShellInstallDir,
@@ -441,22 +442,18 @@ async function checkInstall(conf: CheckConfiguration) {
441442
conf.jsonResult.chrome = chromeJson;
442443
}
443444
const chromeCb = async () => {
444-
const chromeDetected = await findChrome();
445+
const envPath = Deno.env.get("QUARTO_CHROMIUM");
445446
const chromeHsPath = chromeHeadlessShellExecutablePath();
447+
const chromeDetected = await findChrome();
446448
const chromiumTool = installableTool("chromium");
447449
const chromiumQuarto = chromiumTool && await chromiumTool.installed()
448450
? chromiumTool
449451
: undefined;
450-
if (chromeDetected.path !== undefined) {
451-
chromeHeadlessOutput.push(`${kIndent}Using: Chrome found on system`);
452-
chromeHeadlessOutput.push(
453-
`${kIndent}Path: ${chromeDetected.path}`,
454-
);
455-
if (chromeDetected.source) {
456-
chromeHeadlessOutput.push(`${kIndent}Source: ${chromeDetected.source}`);
457-
}
458-
chromeJson["path"] = chromeDetected.path;
459-
chromeJson["source"] = chromeDetected.source;
452+
if (envPath && safeExistsSync(envPath)) {
453+
chromeHeadlessOutput.push(`${kIndent}Using: Chrome from QUARTO_CHROMIUM`);
454+
chromeHeadlessOutput.push(`${kIndent}Path: ${envPath}`);
455+
chromeJson["path"] = envPath;
456+
chromeJson["source"] = "QUARTO_CHROMIUM";
460457
} else if (chromeHsPath !== undefined) {
461458
const version = readInstalledVersion(chromeHeadlessShellInstallDir());
462459
chromeJson["source"] = "quarto-chrome-headless-shell";
@@ -469,6 +466,16 @@ async function checkInstall(conf: CheckConfiguration) {
469466
chromeHeadlessOutput.push(`${kIndent}Version: ${version}`);
470467
chromeJson["version"] = version;
471468
}
469+
} else if (chromeDetected.path !== undefined) {
470+
chromeHeadlessOutput.push(`${kIndent}Using: Chrome found on system`);
471+
chromeHeadlessOutput.push(
472+
`${kIndent}Path: ${chromeDetected.path}`,
473+
);
474+
if (chromeDetected.source) {
475+
chromeHeadlessOutput.push(`${kIndent}Source: ${chromeDetected.source}`);
476+
}
477+
chromeJson["path"] = chromeDetected.path;
478+
chromeJson["source"] = chromeDetected.source;
472479
} else if (chromiumQuarto !== undefined) {
473480
chromeJson["source"] = "quarto";
474481
chromeHeadlessOutput.push(

src/core/puppeteer.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -213,20 +213,8 @@ interface ChromeInfo {
213213
export async function findChrome(): Promise<ChromeInfo> {
214214
let path;
215215
let source;
216-
// First check env var and use this path if specified
217-
const envPath = Deno.env.get("QUARTO_CHROMIUM");
218-
if (envPath) {
219-
debug("[CHROMIUM] Using path specified in QUARTO_CHROMIUM");
220-
if (safeExistsSync(envPath)) {
221-
debug(`[CHROMIUM] Found at ${envPath}, and will be used.`);
222-
return { path: envPath, source: "QUARTO_CHROMIUM" };
223-
} else {
224-
debug(
225-
`[CHROMIUM] Not found at ${envPath}. Check your environment variable valye. Searching now for another binary.`,
226-
);
227-
}
228-
}
229-
// Otherwise, try to find the path based on OS.
216+
// Find Chrome/Edge from OS-specific known locations.
217+
// QUARTO_CHROMIUM env var is handled by callers before calling this function.
230218
if (isMac) {
231219
const programs = [
232220
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
@@ -292,17 +280,31 @@ export async function getBrowserExecutablePath() {
292280

293281
let executablePath: string | undefined = undefined;
294282

295-
// Priority 1: QUARTO_CHROMIUM env var + system Chrome/Edge
296-
if (executablePath === undefined) {
297-
executablePath = (await findChrome()).path;
283+
// Priority 1: QUARTO_CHROMIUM env var
284+
const envPath = Deno.env.get("QUARTO_CHROMIUM");
285+
if (envPath && safeExistsSync(envPath)) {
286+
debug(`[CHROMIUM] Using QUARTO_CHROMIUM: ${envPath}`);
287+
executablePath = envPath;
298288
}
299289

300290
// Priority 2: Quarto-installed chrome-headless-shell
301291
if (executablePath === undefined) {
302292
executablePath = chromeHeadlessShellExecutablePath();
293+
if (executablePath) {
294+
debug(`[CHROMIUM] Using chrome-headless-shell: ${executablePath}`);
295+
}
296+
}
297+
298+
// Priority 3: System Chrome/Edge
299+
if (executablePath === undefined) {
300+
const chromeInfo = await findChrome();
301+
if (chromeInfo.path) {
302+
debug(`[CHROMIUM] Using system Chrome from ${chromeInfo.source}: ${chromeInfo.path}`);
303+
executablePath = chromeInfo.path;
304+
}
303305
}
304306

305-
// Priority 3: Legacy puppeteer-managed Chromium revisions
307+
// Priority 4: Legacy puppeteer-managed Chromium revisions
306308
if (executablePath === undefined && availableRevisions.length > 0) {
307309
// get the latest available revision
308310
availableRevisions.sort((a: string, b: string) => Number(b) - Number(a));

0 commit comments

Comments
 (0)