Skip to content

Commit ce0bf7f

Browse files
committed
Launch Chromium for fresh-chrome, if Chrome is not available
1 parent 9f8194c commit ce0bf7f

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/interceptors/fresh-chrome.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ const readFile = promisify(fs.readFile);
1515

1616
let browsers: _.Dictionary<BrowserInstance> = {};
1717

18+
// Should we launch Chrome, or Chromium, or do we have nothing available at all?
19+
const getChromeBrowserName = async (config: HtkConfig): Promise<string | undefined> => {
20+
const browsers = await getAvailableBrowsers(config.configPath);
21+
22+
return _(browsers)
23+
.map(b => b.name)
24+
.intersection(['chrome', 'chromium'])
25+
.value()[0];
26+
};
27+
1828
export class FreshChrome {
1929
id = 'fresh-chrome';
2030
version = '1.0.0';
@@ -26,12 +36,7 @@ export class FreshChrome {
2636
}
2737

2838
async isActivable() {
29-
const browsers = await getAvailableBrowsers(this.config.configPath);
30-
31-
return _(browsers)
32-
.map(b => b.name)
33-
.includes('chrome')
34-
39+
return !!(await getChromeBrowserName(this.config));
3540
}
3641

3742
async activate(proxyPort: number) {
@@ -44,7 +49,9 @@ export class FreshChrome {
4449
await hideWarningServer.start('https://amiusing.httptoolkit.tech');
4550

4651
const browser = await launchBrowser(hideWarningServer.hideWarningUrl, {
47-
browser: 'chrome',
52+
// Try to launch Chrome if we're not sure - it'll trigger a config update,
53+
// and might find a new install.
54+
browser: (await getChromeBrowserName(this.config)) || 'chrome',
4855
proxy: `https://localhost:${proxyPort}`,
4956
// Don't intercept our warning hiding requests
5057
noProxy: hideWarningServer.host,

0 commit comments

Comments
 (0)