16
16
17
17
from browser_use .browser .events import (
18
18
BrowserLaunchEvent ,
19
+ BrowserStateRequestEvent ,
19
20
BrowserStoppedEvent ,
20
21
FileDownloadedEvent ,
21
22
NavigationCompleteEvent ,
@@ -34,6 +35,7 @@ class DownloadsWatchdog(BaseWatchdog):
34
35
# Events this watchdog listens to (for documentation)
35
36
LISTENS_TO : ClassVar [list [type [BaseEvent [Any ]]]] = [
36
37
BrowserLaunchEvent ,
38
+ BrowserStateRequestEvent ,
37
39
BrowserStoppedEvent ,
38
40
TabCreatedEvent ,
39
41
TabClosedEvent ,
@@ -81,6 +83,26 @@ async def on_TabClosedEvent(self, event: TabClosedEvent) -> None:
81
83
"""Stop monitoring closed tabs."""
82
84
pass # No cleanup needed, browser context handles target lifecycle
83
85
86
+ async def on_BrowserStateRequestEvent (self , event : BrowserStateRequestEvent ) -> None :
87
+ """Handle browser state request events."""
88
+ cdp_session = self .browser_session .agent_focus
89
+ if not cdp_session :
90
+ return
91
+
92
+ url = await self .browser_session .get_current_page_url ()
93
+ if not url :
94
+ return
95
+
96
+ target_id = cdp_session .target_id
97
+ self .event_bus .dispatch (
98
+ NavigationCompleteEvent (
99
+ event_type = "NavigationCompleteEvent" ,
100
+ url = url ,
101
+ target_id = target_id ,
102
+ event_parent_id = event .event_id ,
103
+ )
104
+ )
105
+
84
106
async def on_BrowserStoppedEvent (self , event : BrowserStoppedEvent ) -> None :
85
107
"""Clean up when browser stops."""
86
108
# Cancel all CDP event handler tasks
0 commit comments