File tree Expand file tree Collapse file tree 3 files changed +14
-5
lines changed
Expand file tree Collapse file tree 3 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,7 @@ type McpLaunchOptions = {
6161 userDataDir ?: string ;
6262 headless : boolean ;
6363 isolated : boolean ;
64+ logFile ?: fs . WriteStream ;
6465} ;
6566
6667export async function launch ( options : McpLaunchOptions ) : Promise < Browser > {
@@ -100,7 +101,7 @@ export async function launch(options: McpLaunchOptions): Promise<Browser> {
100101 }
101102
102103 try {
103- return await puppeteer . launch ( {
104+ const browser = await puppeteer . launch ( {
104105 ...connectOptions ,
105106 channel : puppeterChannel ,
106107 executablePath,
@@ -110,6 +111,13 @@ export async function launch(options: McpLaunchOptions): Promise<Browser> {
110111 headless,
111112 args,
112113 } ) ;
114+ if ( options . logFile ) {
115+ // FIXME: we are probably subscribing too late to catch startup logs. We
116+ // should expose the process earlier or expose the getRecentLogs() getter.
117+ browser . process ( ) ?. stderr ?. pipe ( options . logFile ) ;
118+ browser . process ( ) ?. stdout ?. pipe ( options . logFile ) ;
119+ }
120+ return browser ;
113121 } catch ( error ) {
114122 // TODO: check browser logs for `Failed to create a ProcessSingleton for
115123 // your profile directory` instead.
@@ -145,6 +153,7 @@ export async function resolveBrowser(options: {
145153 channel ?: Channel ;
146154 headless : boolean ;
147155 isolated : boolean ;
156+ logFile ?: fs . WriteStream ;
148157} ) {
149158 const browser = options . browserUrl
150159 ? await ensureBrowserConnected ( options . browserUrl )
Original file line number Diff line number Diff line change @@ -113,9 +113,7 @@ export const args = yargsInstance
113113 . help ( )
114114 . parseSync ( ) ;
115115
116- if ( args . logFile ) {
117- saveLogsToFile ( args . logFile ) ;
118- }
116+ const logFile = args . logFile ? saveLogsToFile ( args . logFile ) : undefined ;
119117
120118function readPackageJson ( ) : { version ? : string } {
121119 const currentDir = import . meta. dirname ;
@@ -155,6 +153,7 @@ async function getContext(): Promise<McpContext> {
155153 customDevTools : args . customDevtools ,
156154 channel : args . channel as Channel ,
157155 isolated : args . isolated ,
156+ logFile,
158157 } ) ;
159158 if ( context ?. browser !== browser ) {
160159 context = await McpContext . from ( browser , logger ) ;
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ const namespacesToEnable = [
1414 ...( process . env [ 'DEBUG' ] ? [ process . env [ 'DEBUG' ] ] : [ ] ) ,
1515] ;
1616
17- export function saveLogsToFile ( fileName : string ) {
17+ export function saveLogsToFile ( fileName : string ) : fs . WriteStream {
1818 // Enable overrides everything so we need to add them
1919 debug . enable ( namespacesToEnable . join ( ',' ) ) ;
2020
@@ -27,6 +27,7 @@ export function saveLogsToFile(fileName: string) {
2727 logFile . end ( ) ;
2828 process . exit ( 1 ) ;
2929 } ) ;
30+ return logFile ;
3031}
3132
3233export const logger = debug ( mcpDebugNamespace ) ;
You can’t perform that action at this time.
0 commit comments