fix(browser): default chrome profile to host
This commit is contained in:
@@ -134,6 +134,18 @@ describe("browser tool snapshot maxChars", () => {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("defaults to host when using profile=chrome (even in sandboxed sessions)", async () => {
|
||||||
|
const tool = createBrowserTool({ defaultControlUrl: "http://127.0.0.1:9999" });
|
||||||
|
await tool.execute?.(null, { action: "snapshot", profile: "chrome", format: "ai" });
|
||||||
|
|
||||||
|
expect(browserClientMocks.browserSnapshot).toHaveBeenCalledWith(
|
||||||
|
"http://127.0.0.1:18791",
|
||||||
|
expect.objectContaining({
|
||||||
|
profile: "chrome",
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("browser tool snapshot labels", () => {
|
describe("browser tool snapshot labels", () => {
|
||||||
|
|||||||
@@ -141,8 +141,12 @@ export function createBrowserTool(opts?: {
|
|||||||
const params = args as Record<string, unknown>;
|
const params = args as Record<string, unknown>;
|
||||||
const action = readStringParam(params, "action", { required: true });
|
const action = readStringParam(params, "action", { required: true });
|
||||||
const controlUrl = readStringParam(params, "controlUrl");
|
const controlUrl = readStringParam(params, "controlUrl");
|
||||||
const target = readStringParam(params, "target") as "sandbox" | "host" | "custom" | undefined;
|
|
||||||
const profile = readStringParam(params, "profile");
|
const profile = readStringParam(params, "profile");
|
||||||
|
let target = readStringParam(params, "target") as "sandbox" | "host" | "custom" | undefined;
|
||||||
|
if (profile === "chrome" && !target && !controlUrl?.trim()) {
|
||||||
|
// Chrome extension relay takeover is a host Chrome feature; default to host even in sandboxed sessions.
|
||||||
|
target = "host";
|
||||||
|
}
|
||||||
const baseUrl = resolveBrowserBaseUrl({
|
const baseUrl = resolveBrowserBaseUrl({
|
||||||
target,
|
target,
|
||||||
controlUrl,
|
controlUrl,
|
||||||
@@ -345,10 +349,30 @@ export function createBrowserTool(opts?: {
|
|||||||
if (!request || typeof request !== "object") {
|
if (!request || typeof request !== "object") {
|
||||||
throw new Error("request required");
|
throw new Error("request required");
|
||||||
}
|
}
|
||||||
const result = await browserAct(baseUrl, request as Parameters<typeof browserAct>[1], {
|
try {
|
||||||
profile,
|
const result = await browserAct(
|
||||||
});
|
baseUrl,
|
||||||
return jsonResult(result);
|
request as Parameters<typeof browserAct>[1],
|
||||||
|
{
|
||||||
|
profile,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return jsonResult(result);
|
||||||
|
} catch (err) {
|
||||||
|
const msg = String(err);
|
||||||
|
if (msg.includes("404:") && msg.includes("tab not found") && profile === "chrome") {
|
||||||
|
const tabs = await browserTabs(baseUrl, { profile }).catch(() => []);
|
||||||
|
if (!tabs.length) {
|
||||||
|
throw new Error(
|
||||||
|
'No Chrome tabs are attached via the Clawdbot Browser Relay extension. Click the toolbar icon on the tab you want to control (badge ON), then retry.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
throw new Error(
|
||||||
|
`Chrome tab not found (stale targetId?). Run action=tabs profile="chrome" and use one of the returned targetIds.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unknown action: ${action}`);
|
throw new Error(`Unknown action: ${action}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user