11import _ from 'lodash' ;
2+ import * as path from 'path' ;
23import { generateSPKIFingerprint } from 'mockttp' ;
34
45import { HtkConfig } from '../config' ;
56
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+
612import {
713 getBrowserDetails ,
814 launchBrowser ,
915 BrowserInstance ,
1016 LaunchOptions
1117} from '../browsers' ;
12- import { delay } from '../util/promise' ;
13- import { readFile , deleteFolder } from '../util/fs' ;
14- import { listRunningProcesses , windowsClose , waitForExit } from '../util/process-management' ;
1518import { HideWarningServer } from '../hide-warning-server' ;
1619import { Interceptor } from '.' ;
1720import { logError } from '../error-tracking' ;
@@ -20,6 +23,7 @@ import { WEBEXTENSION_INSTALL } from '../webextension';
2023const getChromiumLaunchOptions = async (
2124 browser : string ,
2225 config : HtkConfig ,
26+ profilePath : string | null | undefined ,
2327 proxyPort : number ,
2428 hideWarningServer : HideWarningServer ,
2529 webExtensionEnabled : boolean
@@ -28,6 +32,7 @@ const getChromiumLaunchOptions = async (
2832 const spkiFingerprint = generateSPKIFingerprint ( certificatePem ) ;
2933
3034 return {
35+ profile : profilePath ,
3136 browser,
3237 proxy : `https://127.0.0.1:${ proxyPort } ` ,
3338 noProxy : [
@@ -95,10 +100,15 @@ abstract class FreshChromiumBasedInterceptor implements Interceptor {
95100
96101 const browserDetails = await getBrowserDetails ( this . config . configPath , this . variantName ) ;
97102
103+ const profilePath = browserDetails && await isSnap ( browserDetails . command )
104+ ? path . join ( await getSnapConfigPath ( this . variantName ) , 'profile' )
105+ : undefined ;
106+
98107 const browser = await launchBrowser ( hideWarningServer . hideWarningUrl ,
99108 await getChromiumLaunchOptions (
100109 browserDetails ? browserDetails . name : this . variantName ,
101110 this . config ,
111+ profilePath ,
102112 proxyPort ,
103113 hideWarningServer ,
104114 ! ! options . webExtensionEnabled
@@ -121,7 +131,7 @@ abstract class FreshChromiumBasedInterceptor implements Interceptor {
121131 if ( process . platform === 'win32' && this . variantName === 'opera' ) return ;
122132 await delay ( 1000 ) ; // No hurry, make sure the browser & related processes have all cleaned up
123133
124- if ( Object . keys ( this . activeBrowsers ) . length === 0 && browserDetails && _ . isString ( browserDetails . profile ) ) {
134+ if ( Object . keys ( this . activeBrowsers ) . length === 0 && typeof browserDetails ? .profile === 'string' ) {
125135 // If we were the last browser, and we have a profile path, and it's in our config
126136 // (just in case something's gone wrong) -> delete the profile to reset everything.
127137
@@ -269,6 +279,7 @@ abstract class ExistingChromiumBasedInterceptor implements Interceptor {
269279 const launchOptions = await getChromiumLaunchOptions (
270280 browserDetails ? browserDetails . name : this . variantName ,
271281 this . config ,
282+ null , // Null profile path ensures we use the system default profile
272283 proxyPort ,
273284 hideWarningServer ,
274285 ! ! options . webExtensionEnabled
@@ -290,8 +301,7 @@ abstract class ExistingChromiumBasedInterceptor implements Interceptor {
290301
291302 const browser = await launchBrowser ( "" , {
292303 ...launchOptions ,
293- skipDefaults : true ,
294- profile : null // Enforce that we use the default profile
304+ skipDefaults : true
295305 } , this . config . configPath ) ;
296306
297307 if ( browser . process . stdout ) browser . process . stdout . pipe ( process . stdout ) ;
0 commit comments