@@ -207,13 +207,12 @@ export class McpContext implements Context {
207207 return this . #requestPage?. pptrPage ?? this . getSelectedPptrPage ( ) ;
208208 }
209209
210- resolveCdpRequestId ( cdpRequestId : string ) : number | undefined {
211- const selectedPage = this . #resolveTargetPage( ) ;
210+ resolveCdpRequestId ( page : McpPage , cdpRequestId : string ) : number | undefined {
212211 if ( ! cdpRequestId ) {
213212 this . logger ( 'no network request' ) ;
214213 return ;
215214 }
216- const request = this . #networkCollector. find ( selectedPage , request => {
215+ const request = this . #networkCollector. find ( page . pptrPage , request => {
217216 // @ts -expect-error id is internal.
218217 return request . id === cdpRequestId ;
219218 } ) ;
@@ -225,31 +224,27 @@ export class McpContext implements Context {
225224 }
226225
227226 resolveCdpElementId (
227+ page : McpPage ,
228228 cdpBackendNodeId : number ,
229- page ?: Page ,
230229 ) : string | undefined {
231230 if ( ! cdpBackendNodeId ) {
232231 this . logger ( 'no cdpBackendNodeId' ) ;
233232 return ;
234233 }
235- const snapshots = page
236- ? [ this . #mcpPages. get ( page ) ?. textSnapshot ] . filter ( Boolean )
237- : [ ...this . #mcpPages. values ( ) ] . map ( mp => mp . textSnapshot ) . filter ( Boolean ) ;
238- if ( ! snapshots . length ) {
234+ const snapshot = page . textSnapshot ;
235+ if ( ! snapshot ) {
239236 this . logger ( 'no text snapshot' ) ;
240237 return ;
241238 }
242239 // TODO: index by backendNodeId instead.
243- for ( const snapshot of snapshots ) {
244- const queue = [ snapshot ! . root ] ;
245- while ( queue . length ) {
246- const current = queue . pop ( ) ! ;
247- if ( current . backendNodeId === cdpBackendNodeId ) {
248- return current . id ;
249- }
250- for ( const child of current . children ) {
251- queue . push ( child ) ;
252- }
240+ const queue = [ snapshot . root ] ;
241+ while ( queue . length ) {
242+ const current = queue . pop ( ) ! ;
243+ if ( current . backendNodeId === cdpBackendNodeId ) {
244+ return current . id ;
245+ }
246+ for ( const child of current . children ) {
247+ queue . push ( child ) ;
253248 }
254249 }
255250 return ;
@@ -971,8 +966,8 @@ export class McpContext implements Context {
971966 if ( data ?. cdpBackendNodeId ) {
972967 snapshot . hasSelectedElement = true ;
973968 snapshot . selectedElementUid = this . resolveCdpElementId (
969+ mcpPage ,
974970 data ?. cdpBackendNodeId ,
975- page ,
976971 ) ;
977972 }
978973
0 commit comments