mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-01 09:10:22 +00:00
fix: stabilize browser existing-session control
This commit is contained in:
@@ -76,4 +76,48 @@ describe("browser manage start timeout option", () => {
|
||||
expect(startCall?.[0]).toMatchObject({ timeout: "60000" });
|
||||
expect(startCall?.[2]).toBeUndefined();
|
||||
});
|
||||
|
||||
it("uses a longer built-in timeout for browser status", async () => {
|
||||
const program = createProgram();
|
||||
await program.parseAsync(["browser", "status"], { from: "user" });
|
||||
|
||||
const statusCall = mocks.callBrowserRequest.mock.calls.find(
|
||||
(call) => ((call[1] ?? {}) as { path?: string }).path === "/",
|
||||
) as [Record<string, unknown>, { path?: string }, { timeoutMs?: number }] | undefined;
|
||||
|
||||
expect(statusCall?.[2]).toEqual({ timeoutMs: 45_000 });
|
||||
});
|
||||
|
||||
it("uses a longer built-in timeout for browser tabs", async () => {
|
||||
const program = createProgram();
|
||||
await program.parseAsync(["browser", "tabs"], { from: "user" });
|
||||
|
||||
const tabsCall = mocks.callBrowserRequest.mock.calls.find(
|
||||
(call) => ((call[1] ?? {}) as { path?: string }).path === "/tabs",
|
||||
) as [Record<string, unknown>, { path?: string }, { timeoutMs?: number }] | undefined;
|
||||
|
||||
expect(tabsCall?.[2]).toEqual({ timeoutMs: 45_000 });
|
||||
});
|
||||
|
||||
it("uses a longer built-in timeout for browser profiles", async () => {
|
||||
const program = createProgram();
|
||||
await program.parseAsync(["browser", "profiles"], { from: "user" });
|
||||
|
||||
const profilesCall = mocks.callBrowserRequest.mock.calls.find(
|
||||
(call) => ((call[1] ?? {}) as { path?: string }).path === "/profiles",
|
||||
) as [Record<string, unknown>, { path?: string }, { timeoutMs?: number }] | undefined;
|
||||
|
||||
expect(profilesCall?.[2]).toEqual({ timeoutMs: 45_000 });
|
||||
});
|
||||
|
||||
it("uses a longer built-in timeout for browser open", async () => {
|
||||
const program = createProgram();
|
||||
await program.parseAsync(["browser", "open", "https://example.com"], { from: "user" });
|
||||
|
||||
const openCall = mocks.callBrowserRequest.mock.calls.find(
|
||||
(call) => ((call[1] ?? {}) as { path?: string }).path === "/tabs/open",
|
||||
) as [Record<string, unknown>, { path?: string }, { timeoutMs?: number }] | undefined;
|
||||
|
||||
expect(openCall?.[2]).toEqual({ timeoutMs: 45_000 });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -13,6 +13,8 @@ import { shortenHomePath } from "../utils.js";
|
||||
import { callBrowserRequest, type BrowserParentOpts } from "./browser-cli-shared.js";
|
||||
import { runCommandWithRuntime } from "./cli-utils.js";
|
||||
|
||||
const BROWSER_MANAGE_REQUEST_TIMEOUT_MS = 45_000;
|
||||
|
||||
function resolveProfileQuery(profile?: string) {
|
||||
return profile ? { profile } : undefined;
|
||||
}
|
||||
@@ -38,7 +40,7 @@ async function callTabAction(
|
||||
query: resolveProfileQuery(profile),
|
||||
body,
|
||||
},
|
||||
{ timeoutMs: 10_000 },
|
||||
{ timeoutMs: BROWSER_MANAGE_REQUEST_TIMEOUT_MS },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -54,7 +56,7 @@ async function fetchBrowserStatus(
|
||||
query: resolveProfileQuery(profile),
|
||||
},
|
||||
{
|
||||
timeoutMs: 1500,
|
||||
timeoutMs: BROWSER_MANAGE_REQUEST_TIMEOUT_MS,
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -196,7 +198,7 @@ export function registerBrowserManageCommands(
|
||||
path: "/tabs",
|
||||
query: resolveProfileQuery(profile),
|
||||
},
|
||||
{ timeoutMs: 3000 },
|
||||
{ timeoutMs: BROWSER_MANAGE_REQUEST_TIMEOUT_MS },
|
||||
);
|
||||
const tabs = result.tabs ?? [];
|
||||
logBrowserTabs(tabs, parent?.json);
|
||||
@@ -220,7 +222,7 @@ export function registerBrowserManageCommands(
|
||||
action: "list",
|
||||
},
|
||||
},
|
||||
{ timeoutMs: 10_000 },
|
||||
{ timeoutMs: BROWSER_MANAGE_REQUEST_TIMEOUT_MS },
|
||||
);
|
||||
const tabs = result.tabs ?? [];
|
||||
logBrowserTabs(tabs, parent?.json);
|
||||
@@ -305,7 +307,7 @@ export function registerBrowserManageCommands(
|
||||
query: resolveProfileQuery(profile),
|
||||
body: { url },
|
||||
},
|
||||
{ timeoutMs: 15000 },
|
||||
{ timeoutMs: BROWSER_MANAGE_REQUEST_TIMEOUT_MS },
|
||||
);
|
||||
if (printJsonResult(parent, tab)) {
|
||||
return;
|
||||
@@ -330,7 +332,7 @@ export function registerBrowserManageCommands(
|
||||
query: resolveProfileQuery(profile),
|
||||
body: { targetId },
|
||||
},
|
||||
{ timeoutMs: 5000 },
|
||||
{ timeoutMs: BROWSER_MANAGE_REQUEST_TIMEOUT_MS },
|
||||
);
|
||||
if (printJsonResult(parent, { ok: true })) {
|
||||
return;
|
||||
@@ -355,7 +357,7 @@ export function registerBrowserManageCommands(
|
||||
path: `/tabs/${encodeURIComponent(targetId.trim())}`,
|
||||
query: resolveProfileQuery(profile),
|
||||
},
|
||||
{ timeoutMs: 5000 },
|
||||
{ timeoutMs: BROWSER_MANAGE_REQUEST_TIMEOUT_MS },
|
||||
);
|
||||
} else {
|
||||
await callBrowserRequest(
|
||||
@@ -366,7 +368,7 @@ export function registerBrowserManageCommands(
|
||||
query: resolveProfileQuery(profile),
|
||||
body: { kind: "close" },
|
||||
},
|
||||
{ timeoutMs: 20000 },
|
||||
{ timeoutMs: BROWSER_MANAGE_REQUEST_TIMEOUT_MS },
|
||||
);
|
||||
}
|
||||
if (printJsonResult(parent, { ok: true })) {
|
||||
@@ -389,7 +391,7 @@ export function registerBrowserManageCommands(
|
||||
method: "GET",
|
||||
path: "/profiles",
|
||||
},
|
||||
{ timeoutMs: 3000 },
|
||||
{ timeoutMs: BROWSER_MANAGE_REQUEST_TIMEOUT_MS },
|
||||
);
|
||||
const profiles = result.profiles ?? [];
|
||||
if (printJsonResult(parent, { profiles })) {
|
||||
|
||||
Reference in New Issue
Block a user