@@ -21,6 +21,7 @@ const canAccess = (path: string) =>
2121
2222const FIREFOX_PREF_REGEX = / \w + _ p r e f \( " ( [ ^ " ] + ) " , ( .* ) \) ; /
2323
24+ let certInstallBrowser : BrowserInstance | undefined ;
2425let browsers : _ . Dictionary < BrowserInstance > = { } ;
2526
2627export class FreshFirefox implements Interceptor {
@@ -127,15 +128,18 @@ export class FreshFirefox implements Interceptor {
127128 await certCheckServer . start ( ) ;
128129 const certInstalled = certCheckServer . waitForSuccess ( ) . catch ( reportError ) ;
129130
130- const browser = await this . startFirefox ( certCheckServer ) ;
131- browser . process . once ( 'exit' , ( ) => certCheckServer . stop ( ) ) ;
131+ certInstallBrowser = await this . startFirefox ( certCheckServer ) ;
132+ certInstallBrowser . process . once ( 'exit' , ( ) => {
133+ certCheckServer . stop ( ) ;
134+ certInstallBrowser = undefined ;
135+ } ) ;
132136 await certInstalled ;
133137 await delay ( 100 ) ; // Tiny delay, so firefox can do initial setup tasks
134- browser . stop ( ) ;
138+ certInstallBrowser . stop ( ) ;
135139 }
136140
137141 async activate ( proxyPort : number ) {
138- if ( this . isActive ( proxyPort ) ) return ;
142+ if ( this . isActive ( proxyPort ) || ! ! certInstallBrowser ) return ;
139143
140144 const firefoxProfile = path . join ( this . config . configPath , 'firefox-profile' ) ;
141145 const firefoxPrefsFile = path . join ( firefoxProfile , 'prefs.js' ) ;
@@ -205,5 +209,9 @@ export class FreshFirefox implements Interceptor {
205209 await Promise . all (
206210 Object . keys ( browsers ) . map ( ( proxyPort ) => this . deactivate ( proxyPort ) )
207211 ) ;
212+ if ( certInstallBrowser ) {
213+ certInstallBrowser . stop ( ) ;
214+ return new Promise ( ( resolve ) => certInstallBrowser ! . process . once ( 'exit' , resolve ) ) ;
215+ }
208216 }
209217} ;
0 commit comments