@@ -134,7 +134,9 @@ export class McpContext implements Context {
134134 this . #options = options ;
135135 this . #headers = options . headers ;
136136
137- this . #networkCollector = new NetworkCollector ( this . browser ) ;
137+ this . #networkCollector = new NetworkCollector ( this . browser , undefined , {
138+ headers : this . #headers,
139+ } ) ;
138140
139141 this . #consoleCollector = new ConsoleCollector ( this . browser , collect => {
140142 return {
@@ -159,42 +161,9 @@ export class McpContext implements Context {
159161
160162 async #init( ) {
161163 const pages = await this . createPagesSnapshot ( ) ;
162- await this . #networkCollector. init ( pages , this . #headers ) ;
164+ await this . #networkCollector. init ( pages ) ;
163165 await this . #consoleCollector. init ( pages ) ;
164166 }
165-
166- /**
167- * Gets the custom headers to add to all network requests.
168- */
169- getHeaders ( ) : Record < string , string > | undefined {
170- return this . #headers;
171- }
172-
173- /**
174- * Sets custom headers to add to all network requests.
175- */
176- setHeaders ( headers : Record < string , string > | undefined ) : void {
177- this . #headers = headers ;
178- // Update all existing pages with the new headers
179- for ( const page of this . #pages) {
180- this . #applyHeadersToPage( page , headers ) ;
181- }
182- }
183-
184- /**
185- * Applies custom headers to a specific page.
186- */
187- async #applyHeadersToPage( page : Page , headers : Record < string , string > | undefined ) : Promise < void > {
188- try {
189- if ( headers ) {
190- await page . setExtraHTTPHeaders ( headers ) ;
191- } else {
192- await page . setExtraHTTPHeaders ( { } ) ;
193- }
194- } catch ( error ) {
195- this . logger ( 'Error applying headers to page:' , error ) ;
196- }
197- }
198167
199168 dispose ( ) {
200169 this . #networkCollector. dispose ( ) ;
@@ -714,6 +683,8 @@ export class McpContext implements Context {
714683 collect ( req ) ;
715684 } ,
716685 } as ListenerMap ;
686+ } , {
687+ headers : this . #headers,
717688 } ) ;
718689 await this . #networkCollector. init ( await this . browser . pages ( ) ) ;
719690 }
0 commit comments