mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-30 02:20:38 +00:00
fix(browser): prefer managed default profile in headless mode
This commit is contained in:
@@ -2,6 +2,7 @@ import { SsrFBlockedError } from "../infra/net/ssrf.js";
|
||||
import { isChromeReachable, resolveOpenClawUserDataDir } from "./chrome.js";
|
||||
import type { ResolvedBrowserProfile } from "./config.js";
|
||||
import { resolveProfile } from "./config.js";
|
||||
import { DEFAULT_OPENCLAW_BROWSER_PROFILE_NAME } from "./constants.js";
|
||||
import { BrowserProfileNotFoundError, toBrowserErrorResponse } from "./errors.js";
|
||||
import { InvalidBrowserNavigationUrlError } from "./navigation-guard.js";
|
||||
import { getBrowserProfileCapabilities } from "./profile-capabilities.js";
|
||||
@@ -40,6 +41,35 @@ export function listKnownProfileNames(state: BrowserServerState): string[] {
|
||||
return [...names];
|
||||
}
|
||||
|
||||
function resolveImplicitProfileName(state: BrowserServerState): string {
|
||||
const defaultProfileName = state.resolved.defaultProfile;
|
||||
if (!state.resolved.headless) {
|
||||
return defaultProfileName;
|
||||
}
|
||||
|
||||
const defaultProfile = resolveProfile(state.resolved, defaultProfileName);
|
||||
if (!defaultProfile) {
|
||||
return defaultProfileName;
|
||||
}
|
||||
|
||||
const capabilities = getBrowserProfileCapabilities(defaultProfile);
|
||||
if (!capabilities.requiresRelay && !capabilities.usesChromeMcp) {
|
||||
return defaultProfileName;
|
||||
}
|
||||
|
||||
const managedProfile = resolveProfile(state.resolved, DEFAULT_OPENCLAW_BROWSER_PROFILE_NAME);
|
||||
if (!managedProfile) {
|
||||
return defaultProfileName;
|
||||
}
|
||||
|
||||
const managedCapabilities = getBrowserProfileCapabilities(managedProfile);
|
||||
if (managedCapabilities.requiresRelay || managedCapabilities.usesChromeMcp) {
|
||||
return defaultProfileName;
|
||||
}
|
||||
|
||||
return managedProfile.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a profile-scoped context for browser operations.
|
||||
*/
|
||||
@@ -129,7 +159,7 @@ export function createBrowserRouteContext(opts: ContextOptions): BrowserRouteCon
|
||||
|
||||
const forProfile = (profileName?: string): ProfileContext => {
|
||||
const current = state();
|
||||
const name = profileName ?? current.resolved.defaultProfile;
|
||||
const name = profileName ?? resolveImplicitProfileName(current);
|
||||
const profile = resolveBrowserProfileWithHotReload({
|
||||
current,
|
||||
refreshConfigFromDisk,
|
||||
|
||||
Reference in New Issue
Block a user