openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
146 lines (145 loc) • 8.81 kB
JavaScript
import { l as normalizeOptionalString } from "../../string-coerce-CCIiB4H7.mjs";
import { r as asNullableRecord } from "../../record-coerce-CVPuDqcc.mjs";
import { t as CONFIG_DIR } from "../../utils-C8YECn2Q.mjs";
import { t as formatCliCommand } from "../../command-format-CqdwUgPk.mjs";
import "../../string-coerce-runtime-BwAZZDf5.mjs";
import "../../text-utility-runtime-Ds8jsG0J.mjs";
import { i as resolveBrowserConfig, o as resolveManagedBrowserHeadlessMode, r as isLocalManagedProfile, s as resolveProfile, t as getManagedBrowserMissingDisplayError } from "../../config-ccOD-Wrr.mjs";
import "../../cli-runtime-DeVPX2l7.mjs";
import { t as getBrowserProfileCapabilities } from "../../profile-capabilities-C9i07NhJ.mjs";
import { a as resolveGoogleChromeExecutableForPlatform, i as resolveBrowserExecutableForPlatform, o as parseBrowserMajorVersion, s as readBrowserVersion, t as assertBrowserExecutableSupportsLaunch } from "../../chrome.executables-BXILxwVX.mjs";
import fs from "node:fs";
import path from "node:path";
//#region extensions/browser/src/doctor-browser.ts
const CHROME_MCP_MIN_MAJOR = 144;
const REMOTE_DEBUGGING_PAGES = [
"chrome://inspect/#remote-debugging",
"brave://inspect/#remote-debugging",
"edge://inspect/#remote-debugging"
].join(", ");
function collectBrowserDoctorProfiles(e, t) {
const n = asNullableRecord(e.browser);
const r = new Set(Object.keys(asNullableRecord(n?.profiles) ?? {}));
const i = normalizeOptionalString(n?.defaultProfile);
if (i) r.add(i);
const a = [...r].flatMap((e) => {
const n = resolveProfile(t, e);
return n ? [n] : [];
}).toSorted((e, t) => e.name.localeCompare(t.name));
return {
managed: a.filter(isLocalManagedProfile),
chromeMcp: a.filter((e) => getBrowserProfileCapabilities(e).usesChromeMcp && !e.cdpUrl)
};
}
async function collectBrowserReadinessFindings(e) {
const t = [];
const report = (e, n, r, i = "https://docs.openclaw.ai/tools/browser/troubleshooting", a = "warning") => {
t.push({
checkId: "core/doctor/browser",
severity: a,
category: n,
message: e,
fixHint: r,
docsUrl: i
});
};
const n = process.platform;
const r = resolveBrowserConfig(e.browser, e);
const { managed: i, chromeMcp: a } = collectBrowserDoctorProfiles(e, r);
const o = i.map((e) => e.name).join(", ");
if (r.enabled && r.extensionRelay.allowLegacyAuth) report("Legacy Browser Relay Authentication is enabled (browser.extensionRelay.allowLegacyAuth=true).", "recommended", "Update paired extensions and external CDP clients to Browser Relay Authentication v2, then set browser.extensionRelay.allowLegacyAuth=false.", "https://docs.openclaw.ai/tools/browser/setup");
if (fs.existsSync(path.join(CONFIG_DIR, "browser", "chrome-extension"))) report("Chrome extension native bootstrap was not inspected; registration status is unavailable in Doctor.", "recommended", `If extension attach does not work, run ${formatCliCommand("openclaw browser extension status --json")}; this may request browser profile access. Run ${formatCliCommand("openclaw browser extension install")} if repair is needed. No action needed if attach works.`, "https://docs.openclaw.ai/tools/browser/setup", "info");
const s = /* @__PURE__ */ new Map();
const c = /* @__PURE__ */ new Map();
const l = i.filter((e) => {
const t = e.executablePath;
if (!s.has(t)) try {
s.set(t, resolveBrowserExecutableForPlatform({
...r,
executablePath: t
}, n));
} catch (e) {
s.set(t, null);
c.set(t, e instanceof Error ? e.message : String(e));
}
try {
const i = s.get(t);
if (i) {
const t = resolveManagedBrowserHeadlessMode(r, e);
assertBrowserExecutableSupportsLaunch(i, t.headless, n);
}
return !i;
} catch (e) {
c.set(t, e instanceof Error ? e.message : String(e));
return true;
}
});
const u = i.map((e) => getManagedBrowserMissingDisplayError(r, e, {
platform: n,
env: process.env
})).filter((e) => e !== null);
const d = n === "linux" && i.length > 0 && !r.noSandbox && process.getuid?.() === 0;
if (l.length > 0) {
const e = l.map((e) => {
const t = r.profiles[e.name];
const n = normalizeOptionalString(t?.executablePath) ? `browser.profiles.${e.name}.executablePath` : "browser.executablePath";
return e.executablePath ? `Correct ${n} to an existing browser executable, or remove it to use browser auto-detection.` : "Install Chrome, Chromium, Brave, or Edge, or set browser.executablePath to an existing browser executable.";
});
report([
`OpenClaw-managed browser profile(s) are configured: ${l.map((e) => e.name).join(", ")}.`,
l.some((e) => e.executablePath) ? "A configured browser executable could not be used for OpenClaw-managed launch." : "No Chromium-based browser executable was found on this host for OpenClaw-managed launch.",
...c.values()
].join("\n"), "fix-now", [...new Set(e)].join("\n"));
}
if (u.length > 0 || d) {
const e = [`OpenClaw-managed browser profile(s) are configured: ${o}.`];
if (u.length > 0) e.push(...u.every((e) => e.headlessSource === "config") ? ["No DISPLAY or WAYLAND_DISPLAY is set, and browser.headless is false. Managed browser launch needs a desktop session, Xvfb, or browser.headless: true."] : u.map((e) => e.message));
if (d) e.push("The Gateway is running as root and browser.noSandbox is false. Chromium commonly requires browser.noSandbox: true in container/root runtimes.");
report(e.join("\n"), "fix-now", "Run the Gateway as a non-root user where possible. Provide a desktop session or set browser.headless=true for managed launch; in a trusted root container, explicitly configure browser.noSandbox=true if required.", "https://docs.openclaw.ai/tools/browser-linux-troubleshooting");
}
if (a.length === 0) return t;
const f = a.filter((e) => e.userDataDir);
const p = a.filter((e) => !e.userDataDir);
const m = a.map((e) => e.name).join(", ");
const h = p.length > 0;
const g = h ? resolveGoogleChromeExecutableForPlatform(n) : null;
let _ = "recommended";
let v = "info";
const y = [`Chrome MCP existing-session is configured for profile(s): ${m}.`];
if (!h) y.push("These profiles use an explicit Chromium user data directory instead of Chrome's default auto-connect path.", `Verify the matching Chromium-based browser is version ${CHROME_MCP_MIN_MAJOR}+ on the same host as the Gateway or node.`);
else if (!g) {
_ = "fix-now";
v = "warning";
const e = p.map((e) => e.name).join(", ");
y.push(`Google Chrome was not found on this host for auto-connect profile(s): ${e}. OpenClaw does not bundle Chrome.`, `Install Google Chrome ${CHROME_MCP_MIN_MAJOR}+ on the same host as the Gateway or node, or set browser.profiles.<name>.userDataDir for a different Chromium-based browser.`);
} else {
const e = readBrowserVersion(g.path);
const t = parseBrowserMajorVersion(e);
y.push(`Chrome path: ${g.path}`);
if (!e || t === null) {
_ = "fix-now";
v = "warning";
y.push(`Could not determine the installed Chrome version. Chrome MCP requires Google Chrome ${CHROME_MCP_MIN_MAJOR}+ on this host.`);
} else if (t < CHROME_MCP_MIN_MAJOR) {
_ = "fix-now";
v = "warning";
y.push(`Detected Chrome ${e}, which is too old for Chrome MCP existing-session attach. Upgrade to Chrome ${CHROME_MCP_MIN_MAJOR}+.`);
} else y.push(`Detected Chrome ${e}.`);
}
y.push(`Enable remote debugging in ${h ? "the browser inspect page" : "that browser's inspect page"} (${REMOTE_DEBUGGING_PAGES}).`, "Keep the browser running and accept the attach consent prompt the first time OpenClaw connects.");
if (h && !g) y.push("Docker, headless, and sandbox browser flows stay on raw CDP; this check only applies to host-local Chrome MCP attach.");
if (h && f.length > 0) y.push(`Profiles with explicit userDataDir ${g ? "still need manual validation of the matching Chromium-based browser" : "skip Chrome auto-detection"}: ${f.map((e) => e.name).join(", ")}.`);
report(y.join("\n"), _, `Use Chromium ${CHROME_MCP_MIN_MAJOR}+ on the Gateway or node host, enable remote debugging (${REMOTE_DEBUGGING_PAGES}), and accept the first attach consent.${_ === "recommended" ? " No action needed if existing-session attach already works." : ""}`, "https://docs.openclaw.ai/tools/browser/existing-session", v);
return t;
}
/** Leave discovery-dependent native-host repair to explicit extension setup. */
async function maybeRepairOwnedChromeExtensionNativeHosts() {
return {
status: "skipped",
reason: "Doctor does not inspect personal browser profiles",
changes: [],
warnings: [`Chrome extension native-host repair skipped: Doctor does not inspect personal browser profiles. Run ${formatCliCommand("openclaw browser extension install")} to repair explicitly.`]
};
}
//#endregion
export { collectBrowserReadinessFindings, maybeRepairOwnedChromeExtensionNativeHosts };