@@ -106,15 +106,15 @@ abstract class FreshChromiumBasedInterceptor implements Interceptor {
106
106
107
107
const browserDetails = await getBrowserDetails ( this . config . configPath , this . variantName ) ;
108
108
109
- const profilePath = browserDetails && await isSnap ( browserDetails . command )
109
+ const snapProfilePath = browserDetails && await isSnap ( browserDetails . command )
110
110
? path . join ( await getSnapConfigPath ( this . variantName ) , 'profile' )
111
111
: undefined ;
112
112
113
113
const browser = await launchBrowser ( hideWarningServer . hideWarningUrl ,
114
114
await getChromiumLaunchOptions (
115
115
browserDetails ? browserDetails . name : this . variantName ,
116
116
this . config ,
117
- profilePath ,
117
+ snapProfilePath ,
118
118
proxyPort ,
119
119
hideWarningServer ,
120
120
! ! options . webExtensionEnabled
@@ -139,22 +139,27 @@ abstract class FreshChromiumBasedInterceptor implements Interceptor {
139
139
if ( process . platform === 'win32' && this . variantName === 'opera' ) return ;
140
140
await delay ( 1000 ) ; // No hurry, make sure the browser & related processes have all cleaned up
141
141
142
- if ( Object . keys ( this . activeBrowsers ) . length === 0 && typeof browserDetails ?. profile === 'string' ) {
143
- // If we were the last browser, and we have a profile path, and it's in our config
144
- // (just in case something's gone wrong) -> delete the profile to reset everything.
145
-
146
- const profilePath = browserDetails . profile ;
147
- if ( ! profilePath . startsWith ( this . config . configPath ) ) {
142
+ const activeBrowserCount = Object . keys ( this . activeBrowsers ) . length ;
143
+ const profilePath = snapProfilePath ?? browserDetails ?. profile ;
144
+ if ( activeBrowserCount === 0 && typeof profilePath === 'string' ) {
145
+ // If we were the last browser and we have a profile path, and it's definitely part of our
146
+ // local/snap config (just in case something's gone wrong) -> delete it & reset everything.
147
+
148
+ if (
149
+ // Part of our local config path:
150
+ ! profilePath . startsWith ( this . config . configPath ) &&
151
+ // Or part of the .httptoolkit dir within a Snap's data dir:
152
+ ! profilePath . includes ( path . join ( 'snap' , this . variantName , 'current' , '.httptoolkit' ) )
153
+ ) {
148
154
logError (
149
155
`Unexpected ${ this . variantName } profile location, not deleting: ${ profilePath } `
150
156
) ;
151
157
} else {
152
- const profileFolder = browserDetails . profile ;
153
- deleteFolder ( profileFolder )
158
+ deleteFolder ( profilePath )
154
159
. catch ( async ( ) => {
155
160
// After 1 error, wait a little and retry
156
161
await delay ( 1000 ) ;
157
- await deleteFolder ( profileFolder ) ;
162
+ await deleteFolder ( profilePath ) ;
158
163
} ) . catch ( console . warn ) ; // If it still fails, just give up, not a big deal
159
164
}
160
165
}
0 commit comments