FIx corner cases (val connection in chrome when using playwright, and action parsing for agent, and accessibility tree xml handling)

This commit is contained in:
Timothyxxx
2024-01-16 22:00:01 +08:00
parent 186bf2e97c
commit 20b1d950a0
5 changed files with 51 additions and 30 deletions

View File

@@ -159,9 +159,19 @@ def get_open_tabs_info(env, config: Dict[str, str]):
tabs_info = []
for context in browser.contexts:
for page in context.pages:
title = page.title()
url = page.url
tabs_info.append({'title': title, 'url': url})
try:
# Wait for the page to finish loading, this prevents the "execution context was destroyed" issue
page.wait_for_load_state('load') # Wait for the 'load' event to complete
title = page.title()
url = page.url
tabs_info.append({'title': title, 'url': url})
except TimeoutError:
# If page loading times out, catch the exception and store the current information in the list
tabs_info.append({'title': 'Load timeout', 'url': page.url})
except Exception as e:
# Catch other potential exceptions that might occur while reading the page title
print(f'Error: {e}')
tabs_info.append({'title': 'Error encountered', 'url': page.url})
browser.close()
return tabs_info