@@ -38,18 +38,23 @@ function targetFilter(target: Target): boolean {
3838 return true ;
3939}
4040
41- const connectOptions : ConnectOptions = {
42- targetFilter,
43- // We do not expect any single CDP command to take more than 10sec.
44- protocolTimeout : 10_000 ,
45- } ;
41+ function getConnectOptions ( protocolTimeout : number ) : ConnectOptions {
42+ return {
43+ targetFilter,
44+ // We do not expect any single CDP command to take more than 10sec.
45+ protocolTimeout,
46+ } ;
47+ }
4648
47- export async function ensureBrowserConnected ( browserURL : string ) {
49+ export async function ensureBrowserConnected (
50+ browserURL : string ,
51+ protocolTimeout = 10_000 ,
52+ ) {
4853 if ( browser ?. connected ) {
4954 return browser ;
5055 }
5156 browser = await puppeteer . connect ( {
52- ...connectOptions ,
57+ ...getConnectOptions ( protocolTimeout ) ,
5358 browserURL,
5459 defaultViewport : null ,
5560 } ) ;
@@ -70,6 +75,7 @@ interface McpLaunchOptions {
7075 height : number ;
7176 } ;
7277 args ?: string [ ] ;
78+ protocolTimeout ?: number ;
7379}
7480
7581export async function launch ( options : McpLaunchOptions ) : Promise < Browser > {
@@ -112,7 +118,7 @@ export async function launch(options: McpLaunchOptions): Promise<Browser> {
112118
113119 try {
114120 const browser = await puppeteer . launch ( {
115- ...connectOptions ,
121+ ...getConnectOptions ( options . protocolTimeout ?? 10_000 ) ,
116122 channel : puppeteerChannel ,
117123 executablePath,
118124 defaultViewport : null ,
@@ -162,6 +168,7 @@ export async function ensureBrowserLaunched(
162168 return browser ;
163169 }
164170 browser = await launch ( options ) ;
171+
165172 return browser ;
166173}
167174
0 commit comments