@@ -81,11 +81,11 @@ export class Chromium extends BrowserType {
8181 return super . launchPersistentContext ( progress , userDataDir , options ) ;
8282 }
8383
84- override async connectOverCDP ( progress : Progress , endpointURL : string , options : { slowMo ?: number , headers ?: types . HeadersArray , isLocal ?: boolean , noDefaults ?: boolean } ) {
84+ override async connectOverCDP ( progress : Progress , endpointURL : string , options : { slowMo ?: number , headers ?: types . HeadersArray , isLocal ?: boolean , noDefaults ?: boolean , artifactsDir ?: string } ) {
8585 return await this . _connectOverCDPInternal ( progress , endpointURL , options ) ;
8686 }
8787
88- async _connectOverCDPInternal ( progress : Progress , endpointURL : string , options : types . LaunchOptions & { headers ?: types . HeadersArray , isLocal ?: boolean , noDefaults ?: boolean } , onClose ?: ( ) => Promise < void > ) {
88+ async _connectOverCDPInternal ( progress : Progress , endpointURL : string , options : types . LaunchOptions & { headers ?: types . HeadersArray , isLocal ?: boolean , noDefaults ?: boolean , artifactsDir ?: string } , onClose ?: ( ) => Promise < void > ) {
8989 let headersMap : { [ key : string ] : string ; } | undefined ;
9090 if ( options . headers )
9191 headersMap = headersArrayToObject ( options . headers , false ) ;
@@ -113,10 +113,17 @@ export class Chromium extends BrowserType {
113113 return this . _connectOverCDPImpl ( progress , chromeTransport , closeAndWait , options , onClose ) ;
114114 }
115115
116- private async _connectOverCDPImpl ( progress : Progress , transport : ConnectionTransport , closeAndWait : ( ) => Promise < void > , options : types . LaunchOptions & { isLocal ?: boolean , noDefaults ?: boolean } , onClose ?: ( ) => Promise < void > ) {
117- const artifactsDir = await progress . race ( fs . promises . mkdtemp ( ARTIFACTS_FOLDER ) ) ;
116+ private async _connectOverCDPImpl ( progress : Progress , transport : ConnectionTransport , closeAndWait : ( ) => Promise < void > , options : types . LaunchOptions & { isLocal ?: boolean , noDefaults ?: boolean , artifactsDir ?: string } , onClose ?: ( ) => Promise < void > ) {
117+ let artifactsDir : string ;
118+ const tempDirectories : string [ ] = [ ] ;
119+ if ( options . artifactsDir ) {
120+ artifactsDir = options . artifactsDir ;
121+ } else {
122+ artifactsDir = await progress . race ( fs . promises . mkdtemp ( ARTIFACTS_FOLDER ) ) ;
123+ tempDirectories . push ( artifactsDir ) ;
124+ }
118125 const doCleanup = async ( ) => {
119- await removeFolders ( [ artifactsDir ] ) ;
126+ await removeFolders ( tempDirectories ) ;
120127 const cb = onClose ;
121128 onClose = undefined ; // Make sure to only call onClose once.
122129 await cb ?.( ) ;
0 commit comments