@@ -62,13 +62,12 @@ def add_task_listener(driver, task_id, max_retries=3):
6262 var eventListener = function (e) {{
6363 if (e.detail.type == 'history') {{
6464 if (e.detail.status === 'success' || e.detail.status === 'error') {{
65- document.removeEventListener('TaskUpdate', eventListener);
6665 callback({{status: e.detail.status, type: 'history', data: e.detail.data}});
66+ document.removeEventListener('TaskUpdate', eventListener); // Optional: remove if you need continuous listening
6767 }}
6868 // Does not do anything when the status is 'running' or 'idle'.
6969 // The status 'interrupted' will never be triggered automatically.
7070 }} else if (e.detail.type == 'screenshot') {{
71- document.removeEventListener('TaskUpdate', eventListener);
7271 callback({{status: e.detail.status, type: 'screenshot', data: e.detail.data}});
7372 }} else {{
7473 throw new Error("Invalid event type received: " + e.detail.type);
@@ -91,7 +90,7 @@ def handle_event(event_data):
9190 # Record history when task stops
9291 result = event_data ["status" ]
9392 # Determine the last action status
94- history = event_data ['data' ]
93+ history = event_data ['data' ]
9594 last_action = history [- 1 ]["action" ]["operation" ]["name" ]
9695 if last_action == "finish" :
9796 result = "success"
@@ -112,6 +111,7 @@ def handle_event(event_data):
112111
113112 while attempts < max_retries :
114113 try :
114+ logging .info ("Setting up event listener..." )
115115 handle_event (driver .execute_async_script (script ))
116116 break
117117 except WebDriverException as e :
0 commit comments