Trisha Tomy commited on
Commit
c8e914e
·
1 Parent(s): a4a1211

trying fixes for loading

Browse files
Files changed (1) hide show
  1. src/proxy_lite/browser/browser.py +36 -36
src/proxy_lite/browser/browser.py CHANGED
@@ -185,48 +185,48 @@ class BrowserSession:
185
  )
186
  async def update_poi(self) -> None:
187
  try:
188
- # Added for robustness based on previous discussions
189
- await self.current_page.wait_for_load_state("networkidle", timeout=180000)
190
- logger.debug("wait_for_load_state('networkidle') completed.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
 
192
- # This is the line that was previously timing out, now with increased timeout.
193
- # Adding explicit try/except around it for specific debugging.
194
  try:
195
- await self.current_page.wait_for_selector("body", timeout=180000, state="visible")
196
  logger.debug("wait_for_selector('body', state='visible') completed.")
197
  except PlaywrightTimeoutError as e:
198
- # --- START TEMPORARY DEBUGGING CODE ---
199
- current_url = self.current_page.url if self.current_page else "N/A"
200
- logger.error(f"DEBUGGING: Playwright Timeout (180s) on body selector at URL: {current_url}")
201
-
202
- html_content = None
203
- try:
204
- if self.current_page:
205
- html_content = await self.current_page.content()
206
- # Log only a snippet of HTML to avoid excessively large logs
207
- logger.error(f"DEBUGGING: HTML Content (first 1000 chars) when timeout occurred:\n{html_content[:1000]}...")
208
- except Exception as html_e:
209
- logger.error(f"DEBUGGING: Could not get HTML content: {html_e}")
210
-
211
- screenshot_b64 = "N/A"
212
- try:
213
- if self.current_page:
214
- # Capture screenshot at lower quality to keep log size manageable
215
- screenshot_bytes = await self.current_page.screenshot(type="jpeg", quality=50)
216
- screenshot_b64 = base64.b64encode(screenshot_bytes).decode("utf-8")
217
- # Log only a very short snippet of base64 string
218
- logger.error(f"DEBUGGING: Base64 Screenshot (truncated) when timeout occurred:\ndata:image/jpeg;base64,{screenshot_b64[:100]}... (full string is much longer)")
219
- except Exception as ss_e:
220
- logger.error(f"DEBUGGING: Could not take screenshot: {ss_e}")
221
-
222
- # Re-raise the original exception to ensure the task still fails,
223
- # but now with crucial debugging information in the logs.
224
- raise e
225
- # --- END TEMPORARY DEBUGGING CODE ---
226
 
227
  except PlaywrightTimeoutError: # This outer catch is for the wait_for_load_state timeout
228
- logger.error(f"Timeout waiting for website load state (networkidle): {self.current_url}")
229
- raise # Re-raise if load_state itself times out
230
 
231
  except Exception as e:
232
  logger.error(f"An unexpected error occurred during page readiness check: {e}")
 
185
  )
186
  async def update_poi(self) -> None:
187
  try:
188
+ # We will use "domcontentloaded" as a base and then wait for specific elements
189
+ await self.current_page.wait_for_load_state("domcontentloaded", timeout=60000) # Reduced timeout for initial load
190
+ logger.debug("wait_for_load_state('domcontentloaded') completed.")
191
+
192
+ # --- MODIFICATION START ---
193
+ # Wait for the "Account Forecasting" heading to be visible
194
+ # Adjust the selector below based on the actual HTML of the Salesforce page.
195
+ # Common selectors could be:
196
+ # - `h1:has-text('Account Forecasting')`
197
+ # - `h2:has-text('Account Forecasting')`
198
+ # - `div.some-class-name:has-text('Account Forecasting')`
199
+ # - `[data-qa-id="account-forecasting-heading"]` (if Salesforce uses data-qa attributes)
200
+ # You might need to inspect the Salesforce page to get the exact selector.
201
+ # For now, let's assume it's an h1 or h2 tag containing the text.
202
+ try:
203
+ await self.current_page.wait_for_selector(
204
+ "h1:has-text('Account Forecasting'), h2:has-text('Account Forecasting')",
205
+ timeout=60000, # Set a reasonable timeout for this specific element
206
+ state="visible"
207
+ )
208
+ logger.debug("Successfully waited for 'Account Forecasting' heading.")
209
+ except PlaywrightTimeoutError as e:
210
+ logger.error(f"Timeout waiting for 'Account Forecasting' heading on URL: {self.current_page.url}")
211
+ # You might want to log more specific HTML/screenshot here if this still times out often
212
+ raise # Re-raise if this critical element doesn't appear
213
 
214
+ # It's still good to wait for the body to be visible, but with a shorter timeout
215
+ # if the previous specific heading check passed.
216
  try:
217
+ await self.current_page.wait_for_selector("body", timeout=30000, state="visible")
218
  logger.debug("wait_for_selector('body', state='visible') completed.")
219
  except PlaywrightTimeoutError as e:
220
+ logger.warning(f"DEBUGGING: Playwright Timeout (30s) on body selector, but 'Account Forecasting' heading was found. This might be acceptable if the page is usable.")
221
+ # We can choose to suppress this specific timeout if the critical element is found,
222
+ # or re-raise it if a fully loaded body is strictly necessary for further actions.
223
+ # For now, let's just log and continue, as the primary issue was full page load.
224
+ pass # Do not re-raise if we've found our key indicator.
225
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
 
227
  except PlaywrightTimeoutError: # This outer catch is for the wait_for_load_state timeout
228
+ logger.error(f"Timeout waiting for website load state (domcontentloaded): {self.current_url}")
229
+ raise # Re-raise if initial load_state itself times out
230
 
231
  except Exception as e:
232
  logger.error(f"An unexpected error occurred during page readiness check: {e}")