Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/browser/runtime/local-cloak/chrome-launch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('chromeLaunchArgs', () => {
const args = chromeLaunchArgs([
'--fingerprint=123', '--enable-automation', '--remote-debugging-pipe', '--remote-debugging-port=0', '--headless',
'--remote-debugging-address=0.0.0.0', '--headless=old',
], '/profiles/work', 43123);
], '/profiles/work', 43123, 'linux');
expect(args).toContain('--remote-debugging-address=127.0.0.1');
expect(args).toContain('--remote-debugging-port=43123');
expect(args).toContain('--user-data-dir=/profiles/work');
Expand All @@ -52,6 +52,13 @@ describe('chromeLaunchArgs', () => {
expect(args).not.toContain('--headless');
expect(args).not.toContain('--headless=old');
expect(args).not.toContain('--remote-debugging-address=0.0.0.0');
expect(args).not.toContain('--disable-features=DestroyProfileOnBrowserClose');
});

it('keeps the profile loaded after its last visible window closes on macOS', () => {
const args = chromeLaunchArgs(['--fingerprint=123'], '/profiles/work', 43123, 'darwin');

expect(args).toContain('--disable-features=DestroyProfileOnBrowserClose');
});
});

Expand Down
10 changes: 8 additions & 2 deletions src/browser/runtime/local-cloak/chrome-launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ export async function allocateNonzeroLoopbackPort(): Promise<number> {
return port;
}

export function chromeLaunchArgs(baseArgs: readonly string[], userDataDir: string, port: number): string[] {
export function chromeLaunchArgs(
baseArgs: readonly string[],
userDataDir: string,
port: number,
platform: NodeJS.Platform,
): string[] {
const filtered = baseArgs.filter(arg => arg !== '--enable-automation'
&& !arg.startsWith('--headless')
&& arg !== '--remote-debugging-pipe'
Expand All @@ -62,6 +67,7 @@ export function chromeLaunchArgs(baseArgs: readonly string[], userDataDir: strin
&& !arg.startsWith('--user-data-dir='));
return [
...filtered,
...(platform === 'darwin' ? ['--disable-features=DestroyProfileOnBrowserClose'] : []),
`--user-data-dir=${userDataDir}`,
'--remote-debugging-address=127.0.0.1',
`--remote-debugging-port=${port}`,
Expand Down Expand Up @@ -140,7 +146,7 @@ export async function launchChromePersistentContext(
let pids: number[] = [];
let launchedPid: number | undefined;
try {
const args = chromeLaunchArgs(launchOptions.args ?? [], options.userDataDir, port);
const args = chromeLaunchArgs(launchOptions.args ?? [], options.userDataDir, port, deps.platform);
launchedPid = await deps.launch(executablePath, args, deps.platform);
const endpoint = `http://127.0.0.1:${port}`;
const deadline = deps.now() + READINESS_TIMEOUT_MS;
Expand Down
Loading