@@ -50,7 +50,7 @@ class ContextHandler extends BaseHandler {
5050
5151 async handleClock ( command , method ) {
5252 const context = this . validateResource ( this . contexts , command . contextId , 'Context' ) ?. context ;
53-
53+
5454 const registry = CommandRegistry . create ( {
5555 install : async ( ) => {
5656 await context . clock . install ( command . options ) ;
@@ -148,24 +148,24 @@ class ContextHandler extends BaseHandler {
148148 async waitForPopup ( context , command ) {
149149 const timeout = command . timeout || 30000 ;
150150 const requestId = command . requestId || this . generateId ( 'popup_req' ) ;
151-
152- logger . info ( 'Starting context popup coordination' , {
153- contextId : command . contextId ,
154- timeout,
155- requestId
151+
152+ logger . info ( 'Starting context popup coordination' , {
153+ contextId : command . contextId ,
154+ timeout,
155+ requestId
156156 } ) ;
157-
157+
158158 // Create coordination phases
159159 const phases = PopupCoordinator . createPopupPhases ( 'context' , {
160160 pages : this . pages ,
161161 pageContexts : this . pageContexts ,
162162 setupPageEventListeners : this . setupPageEventListeners ?. bind ( this ) ,
163163 generateId : this . generateId . bind ( this )
164164 } ) ;
165-
165+
166166 // Register the async command
167167 globalCoordinator . registerAsyncCommand ( requestId , phases ) ;
168-
168+
169169 try {
170170 // Start execution with initial data
171171 const result = await globalCoordinator . executeNextPhase ( requestId , {
@@ -174,29 +174,29 @@ class ContextHandler extends BaseHandler {
174174 timeout,
175175 requestId
176176 } ) ;
177-
177+
178178 if ( result . type === 'callback' ) {
179179 // Command is waiting for callback - this is expected for popup coordination
180180 logger . debug ( 'Context popup coordination waiting for callback' , { requestId, callbackType : result . callbackType } ) ;
181181 return result ;
182182 }
183-
183+
184184 if ( result . completed ) {
185185 const validation = PopupCoordinator . validatePopupResult ( result . result ) ;
186186 if ( ! validation . valid ) {
187187 logger . error ( 'Invalid popup result' , { requestId, error : validation . error } ) ;
188188 return { popupPageId : null } ;
189189 }
190-
190+
191191 return result . result ;
192192 }
193-
193+
194194 return { popupPageId : null } ;
195-
195+
196196 } catch ( error ) {
197- logger . error ( 'Context popup coordination failed' , {
198- requestId,
199- error : error . message
197+ logger . error ( 'Context popup coordination failed' , {
198+ requestId,
199+ error : error . message
200200 } ) ;
201201 return { popupPageId : null } ;
202202 }
@@ -232,6 +232,7 @@ class PageHandler extends BaseHandler {
232232 goBack : ( ) => page . goBack ( command . options ) ,
233233 goForward : ( ) => page . goForward ( command . options ) ,
234234 reload : ( ) => page . reload ( command . options ) ,
235+ waitForLoadState : ( ) => page . waitForLoadState ( command . state || 'load' , command . options ) ,
235236 frames : ( ) => this . getFrames ( page ) ,
236237 frame : ( ) => this . getFrame ( page , command ) ,
237238 waitForPopup : ( ) => this . waitForPopup ( page , command )
@@ -370,24 +371,24 @@ class PageHandler extends BaseHandler {
370371 async waitForPopup ( page , command ) {
371372 const timeout = command . timeout || 30000 ;
372373 const requestId = command . requestId || this . generateId ( 'popup_req' ) ;
373-
374- logger . info ( 'Starting page popup coordination' , {
375- pageId : command . pageId ,
376- timeout,
377- requestId
374+
375+ logger . info ( 'Starting page popup coordination' , {
376+ pageId : command . pageId ,
377+ timeout,
378+ requestId
378379 } ) ;
379-
380+
380381 // Create coordination phases
381382 const phases = PopupCoordinator . createPopupPhases ( 'page' , {
382383 pages : this . pages ,
383384 pageContexts : this . pageContexts ,
384385 setupPageEventListeners : this . setupPageEventListeners ?. bind ( this ) ,
385386 generateId : this . generateId . bind ( this )
386387 } ) ;
387-
388+
388389 // Register the async command
389390 globalCoordinator . registerAsyncCommand ( requestId , phases ) ;
390-
391+
391392 try {
392393 // Start execution with initial data
393394 const result = await globalCoordinator . executeNextPhase ( requestId , {
@@ -396,58 +397,58 @@ class PageHandler extends BaseHandler {
396397 timeout,
397398 requestId
398399 } ) ;
399-
400+
400401 if ( result . type === 'callback' ) {
401402 // Command is waiting for callback - this is expected for popup coordination
402403 logger . debug ( 'Page popup coordination waiting for callback' , { requestId, callbackType : result . callbackType } ) ;
403404 return result ;
404405 }
405-
406+
406407 if ( result . completed ) {
407408 const validation = PopupCoordinator . validatePopupResult ( result . result ) ;
408409 if ( ! validation . valid ) {
409410 logger . error ( 'Invalid popup result' , { requestId, error : validation . error } ) ;
410411 return { popupPageId : null } ;
411412 }
412-
413+
413414 // Ensure popup page is registered in main pages Map
414415 const popupPageId = result . result . popupPageId ;
415416 const popup = result . result . popup ;
416-
417+
417418 if ( popup && ! this . pages . has ( popupPageId ) ) {
418419 // Re-register the popup page in the main pages Map
419420 this . pages . set ( popupPageId , popup ) ;
420-
421+
421422 // Set up context mapping
422423 const contextId = this . pageContexts . get ( command . pageId ) ;
423424 if ( contextId ) {
424425 this . pageContexts . set ( popupPageId , contextId ) ;
425426 }
426-
427+
427428 logger . debug ( 'Re-registered popup page in main pages Map' , {
428429 popupPageId,
429430 contextId,
430431 totalPages : this . pages . size
431432 } ) ;
432433 }
433-
434+
434435 // Verify registration before returning
435436 const isRegistered = this . pages . has ( popupPageId ) ;
436437 logger . info ( 'Page popup coordination completed' , {
437438 popupPageId,
438439 isRegistered,
439440 totalPages : this . pages . size
440441 } ) ;
441-
442+
442443 return result . result ;
443444 }
444-
445+
445446 return { popupPageId : null } ;
446-
447+
447448 } catch ( error ) {
448- logger . error ( 'Page popup coordination failed' , {
449- requestId,
450- error : error . message
449+ logger . error ( 'Page popup coordination failed' , {
450+ requestId,
451+ error : error . message
451452 } ) ;
452453 return { popupPageId : null } ;
453454 }
@@ -532,25 +533,25 @@ class LocatorHandler extends BaseHandler {
532533 }
533534
534535 async handleDragAndDrop ( page , command ) {
535- logger . debug ( 'Handling drag and drop' , {
536- selector : command . selector ,
537- target : command . target ,
538- options : command . options
536+ logger . debug ( 'Handling drag and drop' , {
537+ selector : command . selector ,
538+ target : command . target ,
539+ options : command . options
539540 } ) ;
540-
541+
541542 try {
542543 // Use page.dragAndDrop which is the native Playwright method
543544 await page . dragAndDrop ( command . selector , command . target , {
544545 strict : true ,
545546 ...command . options
546547 } ) ;
547-
548+
548549 return this . createValueResult ( true ) ;
549550 } catch ( error ) {
550- logger . error ( 'Drag and drop failed' , {
551- selector : command . selector ,
552- target : command . target ,
553- error : error . message
551+ logger . error ( 'Drag and drop failed' , {
552+ selector : command . selector ,
553+ target : command . target ,
554+ error : error . message
554555 } ) ;
555556 throw error ;
556557 }
@@ -603,7 +604,7 @@ class FrameHandler extends BaseHandler {
603604 name : ( ) => evalInFrame ( ( ) => window . name || '' ) . then ( v => this . createValueResult ( v ?? '' ) ) ,
604605 url : ( ) => evalInFrame ( ( ) => document . location . href ) . then ( v => this . createValueResult ( v ?? '' ) ) ,
605606 isDetached : ( ) => this . checkDetached ( isMainFrame , frameLocator ) ,
606- waitForLoadState : ( ) => this . waitForLoadState ( page , frameLocator , isMainFrame , command ) ,
607+ waitForLoadState : ( ) => isMainFrame ? page . waitForLoadState ( command . state || 'load' , command . options ) : this . waitForLoadState ( page , frameLocator , isMainFrame , command ) ,
607608 parent : ( ) => this . getParent ( isMainFrame , command . frameSelector ) ,
608609 children : ( ) => this . getChildren ( page , frameLocator , isMainFrame , command . frameSelector )
609610 } ) ;
0 commit comments