Skip to content

Commit 8070737

Browse files
author
maebahesioru
committed
fix: improve submission verification - increase timeouts and add fallback on TimeoutError
1 parent 152daa1 commit 8070737

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

src/browser/page_controller.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,20 +1196,28 @@ async def _verify_images_uploaded(self, expected_count: int, check_client_discon
11961196

11971197
async def _verify_submission(self, prompt_textarea_locator: Locator, original_content: str) -> bool:
11981198
try:
1199-
current_content = await prompt_textarea_locator.last.input_value(timeout=1500) or ''
1199+
current_content = await prompt_textarea_locator.last.input_value(timeout=3000) or ''
12001200
if original_content and not current_content.strip():
12011201
self.logger.info(f'[{self.req_id}] Verification Method 1: Textarea cleared, submission successful.')
12021202
return True
12031203
submit_button_locator = self.page.locator(SUBMIT_BUTTON_SELECTOR)
1204-
if await submit_button_locator.is_disabled(timeout=1500):
1204+
if await submit_button_locator.is_disabled(timeout=3000):
12051205
self.logger.info(f'[{self.req_id}] Verification Method 2: Submit button is disabled, submission successful.')
12061206
return True
12071207
response_container = self.page.locator(RESPONSE_CONTAINER_SELECTOR)
1208-
if await response_container.count() > 0 and await response_container.last.is_visible(timeout=1000):
1208+
if await response_container.count() > 0 and await response_container.last.is_visible(timeout=2000):
12091209
self.logger.info(f'[{self.req_id}] Verification Method 3: New response container detected, submission successful.')
12101210
return True
12111211
except Exception as verify_err:
12121212
self.logger.warning(f'[{self.req_id}] Could not confirm submission during verification: {type(verify_err).__name__}')
1213+
# Even if verification timed out, check if response already started
1214+
try:
1215+
response_container = self.page.locator(RESPONSE_CONTAINER_SELECTOR)
1216+
if await response_container.count() > 0 and await response_container.last.is_visible(timeout=1000):
1217+
self.logger.info(f'[{self.req_id}] Verification fallback: Response container visible, submission successful.')
1218+
return True
1219+
except Exception:
1220+
pass
12131221
return False
12141222
return False
12151223

@@ -1240,15 +1248,15 @@ async def _try_shortcut_submit(self, prompt_textarea_locator, check_client_disco
12401248
original_content = await prompt_textarea_locator.input_value(timeout=2000) or ''
12411249
self.logger.info(f'[{self.req_id}] - Attempting {shortcut_modifier}+Enter...')
12421250
await self.page.keyboard.press(f'{shortcut_modifier}+Enter')
1243-
await asyncio.sleep(1.5)
1251+
await asyncio.sleep(2.5)
12441252
if await self._verify_submission(prompt_textarea_locator, original_content):
12451253
self.logger.info(f'[{self.req_id}] ✅ Success with {shortcut_modifier}+Enter.')
12461254
return True
12471255
self.logger.warning(f'[{self.req_id}] - {shortcut_modifier}+Enter submission failed verification.')
12481256
self.logger.info(f'[{self.req_id}] - Attempting Enter...')
12491257
await prompt_textarea_locator.focus(timeout=5000)
12501258
await self.page.keyboard.press('Enter')
1251-
await asyncio.sleep(1.5)
1259+
await asyncio.sleep(2.5)
12521260
if await self._verify_submission(prompt_textarea_locator, original_content):
12531261
self.logger.info(f'[{self.req_id}] ✅ Success with Enter.')
12541262
return True

0 commit comments

Comments
 (0)