@@ -281,6 +281,9 @@ async function initBrowser(sessionId?: string, config:any={}) {
281281 config [ "userDataDir" ] = config [ "userDataDir" ] || `${ config ?. inDocker ? '/sessions' : config ?. sessionDataPath || '.' } /_IGNORE_${ config ?. sessionId || 'session' } `
282282 }
283283 if ( config ?. corsFix ) args . push ( '--disable-web-security' ) ;
284+ if ( config [ "userDataDir" ] && ! fs . existsSync ( config [ "userDataDir" ] ) ) {
285+ fs . mkdirSync ( config [ "userDataDir" ] , { recursive : true } ) ;
286+ }
284287 const browser = ( config ?. browserWSEndpoint ) ? await puppeteer . connect ( { ...config } ) : await puppeteer . launch ( {
285288 headless : true ,
286289 args,
@@ -331,21 +334,21 @@ ON_DEATH(async () => {
331334/**
332335 * @internal
333336 */
334- export const kill = async ( p : Page , b ?: Browser , exit ?: boolean ) => {
337+ export const kill = async ( p : Page , b ?: Browser , exit ?: boolean , pid ?: number ) => {
335338 const killBrowser = async ( browser ?: Browser ) => {
336339 if ( ! browser ) return ;
337- const pid = browser ?. process ( ) ? browser ?. process ( ) . pid : null ;
340+ pid = browser ?. process ( ) ? browser ?. process ( ) . pid : null ;
338341 if ( ! pid ) return ;
339342 if ( ! p ?. isClosed ( ) ) await p ?. close ( ) ;
340343 if ( browser ) await browser ?. close ( ) . catch ( ( ) => { } ) ;
341- if ( pid ) treekill ( pid , 'SIGKILL' )
342344 }
343345 if ( p ) {
344- const browser = p ?. browser ( ) ;
346+ const browser = p ?. browser && typeof p ?. browser === 'function' && p ?. browser ( ) ;
345347 await killBrowser ( browser ) ;
346348 } else if ( b ) {
347349 await killBrowser ( b ) ;
348350 }
351+ if ( pid ) treekill ( pid , 'SIGKILL' )
349352 if ( exit ) process . exit ( ) ;
350353 return ;
351354}
0 commit comments