Skip to content

Commit 72d775e

Browse files
rogerdigitalsteipete
authored andcommitted
fix: stop forcing an extra blank tab on browser launch
1 parent 58c3f86 commit 72d775e

2 files changed

Lines changed: 90 additions & 35 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { describe, expect, it } from "vitest";
2+
import { buildOpenClawChromeLaunchArgs } from "./chrome.js";
3+
4+
describe("browser chrome launch args", () => {
5+
it("does not force an about:blank tab at startup", () => {
6+
const args = buildOpenClawChromeLaunchArgs({
7+
resolved: {
8+
enabled: true,
9+
controlPort: 18791,
10+
cdpProtocol: "http",
11+
cdpHost: "127.0.0.1",
12+
cdpIsLoopback: true,
13+
cdpPortRangeStart: 18800,
14+
cdpPortRangeEnd: 18810,
15+
evaluateEnabled: false,
16+
remoteCdpTimeoutMs: 1500,
17+
remoteCdpHandshakeTimeoutMs: 3000,
18+
extraArgs: [],
19+
color: "#FF4500",
20+
headless: false,
21+
noSandbox: false,
22+
attachOnly: false,
23+
ssrfPolicy: { allowPrivateNetwork: true },
24+
defaultProfile: "openclaw",
25+
profiles: {
26+
openclaw: { cdpPort: 18800, color: "#FF4500" },
27+
},
28+
},
29+
profile: {
30+
name: "openclaw",
31+
cdpUrl: "http://127.0.0.1:18800",
32+
cdpPort: 18800,
33+
cdpHost: "127.0.0.1",
34+
cdpProtocol: "http",
35+
cdpPath: "",
36+
cdpIsLoopback: true,
37+
color: "#FF4500",
38+
auth: undefined,
39+
},
40+
userDataDir: "/tmp/openclaw-test-user-data",
41+
});
42+
43+
expect(args).not.toContain("about:blank");
44+
expect(args).toContain("--remote-debugging-port=18800");
45+
expect(args).toContain("--user-data-dir=/tmp/openclaw-test-user-data");
46+
});
47+
});

src/browser/chrome.ts

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,44 @@ function cdpUrlForPort(cdpPort: number) {
8585
return `http://127.0.0.1:${cdpPort}`;
8686
}
8787

88+
export function buildOpenClawChromeLaunchArgs(params: {
89+
resolved: ResolvedBrowserConfig;
90+
profile: ResolvedBrowserProfile;
91+
userDataDir: string;
92+
}): string[] {
93+
const { resolved, profile, userDataDir } = params;
94+
const args: string[] = [
95+
`--remote-debugging-port=${profile.cdpPort}`,
96+
`--user-data-dir=${userDataDir}`,
97+
"--no-first-run",
98+
"--no-default-browser-check",
99+
"--disable-sync",
100+
"--disable-background-networking",
101+
"--disable-component-update",
102+
"--disable-features=Translate,MediaRouter",
103+
"--disable-session-crashed-bubble",
104+
"--hide-crash-restore-bubble",
105+
"--password-store=basic",
106+
];
107+
108+
if (resolved.headless) {
109+
args.push("--headless=new");
110+
args.push("--disable-gpu");
111+
}
112+
if (resolved.noSandbox) {
113+
args.push("--no-sandbox");
114+
args.push("--disable-setuid-sandbox");
115+
}
116+
if (process.platform === "linux") {
117+
args.push("--disable-dev-shm-usage");
118+
}
119+
if (resolved.extraArgs.length > 0) {
120+
args.push(...resolved.extraArgs);
121+
}
122+
123+
return args;
124+
}
125+
88126
async function canOpenWebSocket(url: string, timeoutMs: number): Promise<boolean> {
89127
return new Promise<boolean>((resolve) => {
90128
const ws = openCdpWebSocket(url, { handshakeTimeoutMs: timeoutMs });
@@ -280,41 +318,11 @@ export async function launchOpenClawChrome(
280318

281319
// First launch to create preference files if missing, then decorate and relaunch.
282320
const spawnOnce = () => {
283-
const args: string[] = [
284-
`--remote-debugging-port=${profile.cdpPort}`,
285-
`--user-data-dir=${userDataDir}`,
286-
"--no-first-run",
287-
"--no-default-browser-check",
288-
"--disable-sync",
289-
"--disable-background-networking",
290-
"--disable-component-update",
291-
"--disable-features=Translate,MediaRouter",
292-
"--disable-session-crashed-bubble",
293-
"--hide-crash-restore-bubble",
294-
"--password-store=basic",
295-
];
296-
297-
if (resolved.headless) {
298-
// Best-effort; older Chromes may ignore.
299-
args.push("--headless=new");
300-
args.push("--disable-gpu");
301-
}
302-
if (resolved.noSandbox) {
303-
args.push("--no-sandbox");
304-
args.push("--disable-setuid-sandbox");
305-
}
306-
if (process.platform === "linux") {
307-
args.push("--disable-dev-shm-usage");
308-
}
309-
310-
// Append user-configured extra arguments (e.g., stealth flags, window size)
311-
if (resolved.extraArgs.length > 0) {
312-
args.push(...resolved.extraArgs);
313-
}
314-
315-
// Always open a blank tab to ensure a target exists.
316-
args.push("about:blank");
317-
321+
const args = buildOpenClawChromeLaunchArgs({
322+
resolved,
323+
profile,
324+
userDataDir,
325+
});
318326
return spawn(exe.path, args, {
319327
stdio: "pipe",
320328
env: {

0 commit comments

Comments
 (0)