Skip to content

Commit cde75f1

Browse files
committed
fix(browser): separate upload filesystem locality
1 parent 6c4713d commit cde75f1

4 files changed

Lines changed: 40 additions & 2 deletions

File tree

‎extensions/browser/src/browser/profile-capabilities.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ type BrowserProfileMode =
1515
type BrowserProfileCapabilities = {
1616
mode: BrowserProfileMode;
1717
isRemote: boolean;
18+
/** Browser process reads paths from the same filesystem as OpenClaw. */
19+
browserFilesystemLocal: boolean;
1820
/** Profile uses the Chrome DevTools MCP server (existing-session driver). */
1921
usesChromeMcp: boolean;
2022
usesPersistentPlaywright: boolean;
@@ -32,6 +34,7 @@ export function getBrowserProfileCapabilities(
3234
return {
3335
mode: "local-existing-session",
3436
isRemote: false,
37+
browserFilesystemLocal: false,
3538
usesChromeMcp: true,
3639
usesPersistentPlaywright: false,
3740
supportsPerTabWs: false,
@@ -48,6 +51,7 @@ export function getBrowserProfileCapabilities(
4851
return {
4952
mode: "local-extension",
5053
isRemote: false,
54+
browserFilesystemLocal: true,
5155
usesChromeMcp: false,
5256
usesPersistentPlaywright: true,
5357
supportsPerTabWs: false,
@@ -61,6 +65,7 @@ export function getBrowserProfileCapabilities(
6165
return {
6266
mode: "remote-cdp",
6367
isRemote: true,
68+
browserFilesystemLocal: false,
6469
usesChromeMcp: false,
6570
usesPersistentPlaywright: true,
6671
supportsPerTabWs: false,
@@ -73,6 +78,9 @@ export function getBrowserProfileCapabilities(
7378
return {
7479
mode: "local-managed",
7580
isRemote: false,
81+
// A loopback attach-only endpoint can terminate in Docker or a tunnel.
82+
// Only an OpenClaw-owned browser is known to share this filesystem.
83+
browserFilesystemLocal: !profile.attachOnly,
7684
usesChromeMcp: false,
7785
usesPersistentPlaywright: false,
7886
supportsPerTabWs: true,

‎extensions/browser/src/browser/pw-tools-core.interactions.set-input-files.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ describe("setInputFilesViaPlaywright", () => {
340340

341341
await setInputFilesViaPlaywright({
342342
cdpUrl: "http://127.0.0.1:18792",
343+
browserFilesystemLocal: false,
343344
targetId: "T1",
344345
inputRef: "e7",
345346
paths: ["/tmp/openclaw/uploads/ok.txt"],

‎extensions/browser/src/browser/routes/agent.act.hooks.current-url-guard.test.ts‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,14 @@ vi.mock("../pw-ai-module.js", () => ({
3636

3737
const { registerBrowserAgentActHookRoutes } = await import("./agent.act.hooks.js");
3838

39-
function createProfileContext(options?: { driver?: "openclaw" | "extension"; tabUrl?: string }) {
39+
function createProfileContext(options?: {
40+
attachOnly?: boolean;
41+
driver?: "openclaw" | "extension";
42+
tabUrl?: string;
43+
}) {
4044
return {
4145
profile: {
46+
attachOnly: options?.attachOnly ?? false,
4247
cdpIsLoopback: true,
4348
cdpUrl: "http://127.0.0.1:9222",
4449
driver: options?.driver ?? ("openclaw" as const),
@@ -179,4 +184,28 @@ describe("agent act hook current URL guard", () => {
179184
}),
180185
);
181186
});
187+
188+
it("sends loopback attach-only uploads as payloads for a separate browser filesystem", async () => {
189+
const profileCtx = createProfileContext({
190+
attachOnly: true,
191+
tabUrl: "http://127.0.0.1:8080/upload",
192+
});
193+
194+
const response = await callHook({
195+
path: "/hooks/file-chooser",
196+
body: { paths: ["/tmp/upload.txt"], ref: "upload-button" },
197+
profileCtx,
198+
allowPrivateNetwork: true,
199+
});
200+
201+
expect(response.statusCode).toBe(200);
202+
expect(response.body).toEqual({ ok: true });
203+
expect(pwMocks.uploadViaPlaywright).toHaveBeenCalledWith(
204+
expect.objectContaining({
205+
browserFilesystemLocal: false,
206+
ref: "upload-button",
207+
paths: ["/tmp/upload.txt"],
208+
}),
209+
);
210+
});
182211
});

‎extensions/browser/src/browser/routes/agent.act.hooks.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export function registerBrowserAgentActHookRoutes(
8585
return;
8686
}
8787

88-
const browserFilesystemLocal = !capabilities.isRemote;
88+
const browserFilesystemLocal = capabilities.browserFilesystemLocal;
8989
if (inputRef || element) {
9090
if (ref) {
9191
return jsonError(res, 400, "ref cannot be combined with inputRef/element");

0 commit comments

Comments
 (0)