@@ -62,13 +62,12 @@ def add_task_listener(driver, task_id, max_retries=3):
62
62
var eventListener = function (e) {{
63
63
if (e.detail.type == 'history') {{
64
64
if (e.detail.status === 'success' || e.detail.status === 'error') {{
65
- document.removeEventListener('TaskUpdate', eventListener);
66
65
callback({{status: e.detail.status, type: 'history', data: e.detail.data}});
66
+ document.removeEventListener('TaskUpdate', eventListener); // Optional: remove if you need continuous listening
67
67
}}
68
68
// Does not do anything when the status is 'running' or 'idle'.
69
69
// The status 'interrupted' will never be triggered automatically.
70
70
}} else if (e.detail.type == 'screenshot') {{
71
- document.removeEventListener('TaskUpdate', eventListener);
72
71
callback({{status: e.detail.status, type: 'screenshot', data: e.detail.data}});
73
72
}} else {{
74
73
throw new Error("Invalid event type received: " + e.detail.type);
@@ -91,7 +90,7 @@ def handle_event(event_data):
91
90
# Record history when task stops
92
91
result = event_data ["status" ]
93
92
# Determine the last action status
94
- history = event_data ['data' ]
93
+ history = event_data ['data' ]
95
94
last_action = history [- 1 ]["action" ]["operation" ]["name" ]
96
95
if last_action == "finish" :
97
96
result = "success"
@@ -112,6 +111,7 @@ def handle_event(event_data):
112
111
113
112
while attempts < max_retries :
114
113
try :
114
+ logging .info ("Setting up event listener..." )
115
115
handle_event (driver .execute_async_script (script ))
116
116
break
117
117
except WebDriverException as e :
0 commit comments