@@ -589,28 +589,84 @@ async def wait_for_page_ready(
589589 This is designed for cached action execution to ensure the page is ready
590590 before attempting to interact with elements.
591591 """
592+ total_start_time = time .time ()
593+
592594 # 1. Wait for loading indicators to disappear (longest timeout first)
595+ loading_indicator_duration_ms = 0.0
596+ step_start_time = time .time ()
597+ loading_indicator_result = "success"
593598 try :
594599 await self ._wait_for_loading_indicators_gone (timeout_ms = loading_indicator_timeout_ms )
595600 except (TimeoutError , asyncio .TimeoutError ):
601+ loading_indicator_result = "timeout"
596602 LOG .warning ("Loading indicator timeout - some indicators may still be present, proceeding" )
597603 except Exception :
604+ loading_indicator_result = "error"
598605 LOG .warning ("Failed to check loading indicators, proceeding" , exc_info = True )
606+ finally :
607+ loading_indicator_duration_ms = (time .time () - step_start_time ) * 1000
608+ LOG .info (
609+ "page_readiness_check" ,
610+ step = "loading_indicators" ,
611+ result = loading_indicator_result ,
612+ duration_ms = loading_indicator_duration_ms ,
613+ timeout_ms = loading_indicator_timeout_ms ,
614+ )
599615
600616 # 2. Wait for network idle (with short timeout - some pages never go idle)
617+ network_idle_duration_ms = 0.0
618+ step_start_time = time .time ()
619+ network_idle_result = "success"
601620 try :
602621 await self .frame .wait_for_load_state ("networkidle" , timeout = network_idle_timeout_ms )
603- LOG .debug ("Network idle achieved" )
604622 except (TimeoutError , asyncio .TimeoutError ):
623+ network_idle_result = "timeout"
605624 LOG .warning ("Network idle timeout - page may have constant activity, proceeding" )
625+ finally :
626+ network_idle_duration_ms = (time .time () - step_start_time ) * 1000
627+ LOG .info (
628+ "page_readiness_check" ,
629+ step = "network_idle" ,
630+ result = network_idle_result ,
631+ duration_ms = network_idle_duration_ms ,
632+ timeout_ms = network_idle_timeout_ms ,
633+ )
606634
607635 # 3. Wait for DOM to stabilize
636+ dom_stability_duration_ms = 0.0
637+ step_start_time = time .time ()
638+ dom_stability_result = "success"
608639 try :
609640 await self ._wait_for_dom_stable (stable_ms = dom_stable_ms , timeout_ms = dom_stability_timeout_ms )
610641 except (TimeoutError , asyncio .TimeoutError ):
642+ dom_stability_result = "timeout"
611643 LOG .warning ("DOM stability timeout - DOM may still be changing, proceeding" )
612644 except Exception :
645+ dom_stability_result = "error"
613646 LOG .warning ("Failed to check DOM stability, proceeding" , exc_info = True )
647+ finally :
648+ dom_stability_duration_ms = (time .time () - step_start_time ) * 1000
649+ LOG .info (
650+ "page_readiness_check" ,
651+ step = "dom_stability" ,
652+ result = dom_stability_result ,
653+ duration_ms = dom_stability_duration_ms ,
654+ timeout_ms = dom_stability_timeout_ms ,
655+ stable_ms = dom_stable_ms ,
656+ )
657+
658+ # Log total page readiness check duration
659+ total_duration_ms = (time .time () - total_start_time ) * 1000
660+ LOG .info (
661+ "page_readiness_check_complete" ,
662+ total_duration_ms = total_duration_ms ,
663+ loading_indicator_duration_ms = loading_indicator_duration_ms ,
664+ network_idle_duration_ms = network_idle_duration_ms ,
665+ dom_stability_duration_ms = dom_stability_duration_ms ,
666+ loading_indicator_result = loading_indicator_result ,
667+ network_idle_result = network_idle_result ,
668+ dom_stability_result = dom_stability_result ,
669+ )
614670
615671 async def _wait_for_loading_indicators_gone (self , timeout_ms : float = 5000 ) -> None :
616672 """
0 commit comments