import { getChromePath , getChromeCanaryPath , getEdgePath } from '../../../utils' ; import { chromium , Browser , firefox , webkit } from 'playwright' ; export type BrowserName = 'chromium' | 'chrome' | 'chrome-canary' | 'msedge' | 'firefox' | 'webkit' ; export interface LaunchOptions { type { boolean } memberof headless : boolean ; type { string [ ] } memberof args ? : string [ ] ; type { string } memberof downloadsPath ? : string ; type { string } memberof executablePath ? : string ; type { number } memberof timeout ? : number ; type { number } memberof slowMo ? : number ; proxy ? : { type { string } server : string ; type { string } bypass ? : string ; type { string } username ? : string ; type { string } password ? : string ; } ; /**
     * If specified, traces are saved into this directory.
     */ tracesDir ? : string ; } export const defaultLaunchOptions = { headless : true , } ; export async function launchBrowser ( name , options ) { switch ( name ) { case 'chrome' : { if ( options && options . executablePath !== undefined ) { const browser = await chromium . launch ( options ) ; return browser ; } { const chromeOptions = { ... options , executablePath : getChromePath ( ) , } ; const browser = await chromium . launch ( chromeOptions ) ; return browser ; } } case 'chrome-canary' : { if ( options && options . executablePath !== undefined ) { const browser = await chromium . launch ( options ) ; return browser ; } { const chromeOptions = { ... options , executablePath : getChromeCanaryPath ( ) , } ; const browser = await chromium . launch ( chromeOptions ) ; return browser ; } } case 'msedge' : { if ( options && options . executablePath !== undefined ) { const browser = await chromium . launch ( options ) ; return browser ; } { const chromeOptions = { ... options , executablePath : getEdgePath ( ) , } ; const browser = await chromium . launch ( chromeOptions ) ; return browser ; } } case 'chromium' : { const browser = await chromium . launch ( options ) ; return browser ; } case 'firefox' : { const browser = await firefox . launch ( options ) ; return browser ; } case 'webkit' : { const browser = await webkit . launch ( options ) ; return browser ; } default : throw new Error ( `Browser named '${ name }' is unknown. It should be one of 'chrome', 'chromium', 'chrome-canary', 'firefox', 'webkit'` ) ; } }