1
1
import _ from 'lodash' ;
2
+ import * as path from 'path' ;
2
3
import { generateSPKIFingerprint } from 'mockttp' ;
3
4
4
5
import { HtkConfig } from '../config' ;
5
6
7
+ import { delay } from '../util/promise' ;
8
+ import { readFile , deleteFolder } from '../util/fs' ;
9
+ import { listRunningProcesses , windowsClose , waitForExit } from '../util/process-management' ;
10
+ import { getSnapConfigPath , isSnap } from '../util/snap' ;
11
+
6
12
import {
7
13
getBrowserDetails ,
8
14
launchBrowser ,
9
15
BrowserInstance ,
10
16
LaunchOptions
11
17
} from '../browsers' ;
12
- import { delay } from '../util/promise' ;
13
- import { readFile , deleteFolder } from '../util/fs' ;
14
- import { listRunningProcesses , windowsClose , waitForExit } from '../util/process-management' ;
15
18
import { HideWarningServer } from '../hide-warning-server' ;
16
19
import { Interceptor } from '.' ;
17
20
import { logError } from '../error-tracking' ;
@@ -20,6 +23,7 @@ import { WEBEXTENSION_INSTALL } from '../webextension';
20
23
const getChromiumLaunchOptions = async (
21
24
browser : string ,
22
25
config : HtkConfig ,
26
+ profilePath : string | null | undefined ,
23
27
proxyPort : number ,
24
28
hideWarningServer : HideWarningServer ,
25
29
webExtensionEnabled : boolean
@@ -28,6 +32,7 @@ const getChromiumLaunchOptions = async (
28
32
const spkiFingerprint = generateSPKIFingerprint ( certificatePem ) ;
29
33
30
34
return {
35
+ profile : profilePath ,
31
36
browser,
32
37
proxy : `https://127.0.0.1:${ proxyPort } ` ,
33
38
noProxy : [
@@ -95,10 +100,15 @@ abstract class FreshChromiumBasedInterceptor implements Interceptor {
95
100
96
101
const browserDetails = await getBrowserDetails ( this . config . configPath , this . variantName ) ;
97
102
103
+ const profilePath = browserDetails && await isSnap ( browserDetails . command )
104
+ ? path . join ( await getSnapConfigPath ( this . variantName ) , 'profile' )
105
+ : undefined ;
106
+
98
107
const browser = await launchBrowser ( hideWarningServer . hideWarningUrl ,
99
108
await getChromiumLaunchOptions (
100
109
browserDetails ? browserDetails . name : this . variantName ,
101
110
this . config ,
111
+ profilePath ,
102
112
proxyPort ,
103
113
hideWarningServer ,
104
114
! ! options . webExtensionEnabled
@@ -121,7 +131,7 @@ abstract class FreshChromiumBasedInterceptor implements Interceptor {
121
131
if ( process . platform === 'win32' && this . variantName === 'opera' ) return ;
122
132
await delay ( 1000 ) ; // No hurry, make sure the browser & related processes have all cleaned up
123
133
124
- if ( Object . keys ( this . activeBrowsers ) . length === 0 && browserDetails && _ . isString ( browserDetails . profile ) ) {
134
+ if ( Object . keys ( this . activeBrowsers ) . length === 0 && typeof browserDetails ? .profile === 'string' ) {
125
135
// If we were the last browser, and we have a profile path, and it's in our config
126
136
// (just in case something's gone wrong) -> delete the profile to reset everything.
127
137
@@ -269,6 +279,7 @@ abstract class ExistingChromiumBasedInterceptor implements Interceptor {
269
279
const launchOptions = await getChromiumLaunchOptions (
270
280
browserDetails ? browserDetails . name : this . variantName ,
271
281
this . config ,
282
+ null , // Null profile path ensures we use the system default profile
272
283
proxyPort ,
273
284
hideWarningServer ,
274
285
! ! options . webExtensionEnabled
@@ -290,8 +301,7 @@ abstract class ExistingChromiumBasedInterceptor implements Interceptor {
290
301
291
302
const browser = await launchBrowser ( "" , {
292
303
...launchOptions ,
293
- skipDefaults : true ,
294
- profile : null // Enforce that we use the default profile
304
+ skipDefaults : true
295
305
} , this . config . configPath ) ;
296
306
297
307
if ( browser . process . stdout ) browser . process . stdout . pipe ( process . stdout ) ;
0 commit comments