Skip to content

Commit 279223b

Browse files
committed
Fix issues with FF first-run setup in OSX, and disable it in Windows
Previously this only worked in Linux. In Windows, it launches a child process, so we can never get the right pid, so we can't reliably kill it and tidy up as we'd like, and the two-step startup *requires* this, or the second step fails with an error. On Mac, we had a similar problem, but actually it turns out we just needed to wait properly for the exit to propagate and shut everything down. There is a child process (open -a ...), but it shuts down ok anyway.
1 parent c7733a9 commit 279223b

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/interceptors/fresh-firefox.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export class FreshFirefox implements Interceptor {
133133
certInstallBrowser.process.once('close', () => {
134134
certCheckServer.stop();
135135
certInstallBrowser = undefined;
136+
136137
if (certInstalled !== true) {
137138
reportError('Firefox certificate setup failed');
138139
deleteFolder(this.firefoxProfilePath).catch(console.warn);
@@ -142,8 +143,14 @@ export class FreshFirefox implements Interceptor {
142143
await certInstalled;
143144
certInstalled = true;
144145

145-
await delay(100); // Tiny delay, so firefox can do initial setup tasks
146+
await delay(200); // Tiny delay, so firefox can do initial setup tasks
147+
148+
// Tell firefox to shutdown, and wait until it does.
146149
certInstallBrowser.stop();
150+
return new Promise((resolve) => {
151+
if (!certInstallBrowser) return resolve();
152+
else certInstallBrowser.process.once('close', resolve);
153+
});
147154
}
148155

149156
async activate(proxyPort: number) {
@@ -153,14 +160,14 @@ export class FreshFirefox implements Interceptor {
153160

154161
let existingPrefs: _.Dictionary<any> = {};
155162

156-
if (await canAccess(firefoxPrefsFile) === false && process.platform !== 'darwin') {
163+
if (await canAccess(firefoxPrefsFile) === false && process.platform !== 'win32') {
157164
/*
158165
First time, we do a separate pre-usage startup & stop, without the proxy, for certificate setup.
159166
This helps avoid initial Firefox profile setup request noise, and tidies up some awkward UX where
160167
firefox likes to open extra welcome windows/tabs on first run.
161168
162-
Unfortunately, OSX doesn't seem to play nicely with this, so we have to fall back to normal
163-
behaviour in that case.
169+
Unfortunately, Windows doesn't seem to play nicely with this (because it spawns separate child
170+
processes that we can't reliable kill), so we have to fall back to normal behaviour in that case.
164171
*/
165172
await this.setupFirefoxProfile();
166173
}

0 commit comments

Comments
 (0)