Skip to content

Commit 0a8f760

Browse files
committed
Don't use browser-launch default opts for existing chrom*
1 parent be20e09 commit 0a8f760

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/browsers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ export const getAvailableBrowsers = async (configPath: string) => {
7979
return (await getLauncher(configPath)).browsers;
8080
};
8181

82+
export { LaunchOptions };
83+
8284
export const launchBrowser = async (url: string, options: LaunchOptions, configPath: string) => {
8385
const launcher = await getLauncher(configPath);
8486
return await promisify(launcher)(url, options);

src/interceptors/chromium-based-interceptors.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ import { generateSPKIFingerprint } from 'mockttp';
33

44
import { HtkConfig } from '../config';
55

6-
import { getAvailableBrowsers, launchBrowser, BrowserInstance, Browser } from '../browsers';
6+
import {
7+
getAvailableBrowsers,
8+
launchBrowser,
9+
BrowserInstance,
10+
Browser,
11+
LaunchOptions
12+
} from '../browsers';
713
import { delay, readFile, deleteFolder, listRunningProcesses } from '../util';
814
import { HideWarningServer } from '../hide-warning-server';
915
import { Interceptor } from '.';
@@ -21,7 +27,7 @@ const getChromiumLaunchOptions = async (
2127
config: HtkConfig,
2228
proxyPort: number,
2329
hideWarningServer: HideWarningServer
24-
) => {
30+
): Promise<LaunchOptions & { options: Required<LaunchOptions>['options'] }> => {
2531
const certificatePem = await readFile(config.https.certPath, 'utf8');
2632
const spkiFingerprint = generateSPKIFingerprint(certificatePem);
2733

@@ -234,13 +240,21 @@ abstract class ExistingChromiumBasedInterceptor implements Interceptor {
234240
hideWarningServer
235241
);
236242

237-
if (existingPid) {
238-
// If we killed something, use --restore-last-session to ensure it comes back:
239-
launchOptions.options.push('--restore-last-session');
240-
}
243+
// Remove almost all default arguments. Each of these changes behaviour in maybe unexpected
244+
// ways, notably including --disable-restore which actively causes problems.
245+
launchOptions.skipDefaults = true;
246+
launchOptions.options.push(
247+
'--no-default-browser-check',
248+
'--no-first-run',
249+
'--disable-popup-blocking' // Required for hide-warning -> amiusing hop
250+
);
251+
252+
// If we killed something, use --restore-last-session to ensure it comes back:
253+
if (existingPid) launchOptions.options.push('--restore-last-session');
241254

242255
const browser = await launchBrowser(hideWarningServer.hideWarningUrl, {
243256
...launchOptions,
257+
skipDefaults: true,
244258
profile: null // Enforce that we use the default profile
245259
}, this.config.configPath);
246260

0 commit comments

Comments
 (0)