Files
openclaw/src/browser-lifecycle-cleanup.ts
Nicolas 4ac90a5b48 fix: skip browser cleanup when browser is disabled
Skip browser lifecycle cleanup when root browser support or the browser plugin entry is disabled, and make the browser maintenance facade respect activation before cached surface use.

Also stabilize the resource-only MCP runtime test by waiting for the async rejection log that CI can observe late.

Verification:
- pnpm test src/plugin-sdk/browser-maintenance.test.ts src/browser-lifecycle-cleanup.test.ts src/auto-reply/reply/session.test.ts src/gateway/server.sessions.reset-cleanup.test.ts src/agents/auth-profiles/usage.test.ts
- pnpm test src/agents/agent-bundle-mcp-runtime.test.ts
- git diff --check
- pnpm build
- autoreview local: no accepted/actionable findings
- GitHub Actions: CI 26693713166, CodeQL 26693713159, CodeQL Critical Quality 26693713157, OpenGrep PR Diff 26693713125, Workflow Sanity 26693713149, Dependency Guard 26693712478

Co-authored-by: Nicolas Van Eenaeme <nicolas@poison.be>
2026-05-30 21:16:47 +01:00

43 lines
1.2 KiB
TypeScript

import type { OpenClawConfig } from "./config/types.openclaw.js";
import { runBestEffortCleanup } from "./infra/non-fatal-cleanup.js";
import { closeTrackedBrowserTabsForSessions } from "./plugin-sdk/browser-maintenance.js";
function normalizeSessionKeys(sessionKeys: string[]): string[] {
const keys = new Set<string>();
for (const sessionKey of sessionKeys) {
const normalized = sessionKey.trim();
if (normalized) {
keys.add(normalized);
}
}
return [...keys];
}
function isBrowserCleanupDisabled(cfg: OpenClawConfig | undefined): boolean {
return cfg?.browser?.enabled === false || cfg?.plugins?.entries?.browser?.enabled === false;
}
export async function cleanupBrowserSessionsForLifecycleEnd(params: {
cfg?: OpenClawConfig;
sessionKeys: string[];
onWarn?: (message: string) => void;
onError?: (error: unknown) => void;
}): Promise<void> {
if (isBrowserCleanupDisabled(params.cfg)) {
return;
}
const sessionKeys = normalizeSessionKeys(params.sessionKeys);
if (sessionKeys.length === 0) {
return;
}
await runBestEffortCleanup({
cleanup: async () => {
await closeTrackedBrowserTabsForSessions({
sessionKeys,
onWarn: params.onWarn,
});
},
onError: params.onError,
});
}