Skip to content

Automate browser based workflows with AI

Fix script reviewer wait placement: after goto, before interactions (#5268)

pedrohsdbaf1780449010
diff --git a/skyvern/forge/prompts/skyvern/script-reviewer-extraction.j2 b/skyvern/forge/prompts/skyvern/script-reviewer-extraction.j2
index 4f0d3382e..07c1b64be 100644
--- a/skyvern/forge/prompts/skyvern/script-reviewer-extraction.j2
+++ b/skyvern/forge/prompts/skyvern/script-reviewer-extraction.j2
@@ -107,7 +107,24 @@ The user has provided the following instructions for fixing this script. Priorit
{% endif %}
## Slow Page Load / Page Not Ready
-When the error or page text suggests the page wasn't ready for interaction, the script acted too soon. Signs include: blank page messages, "still on X page", loading spinners/overlays, progress indicators, or the page text showing a transitional state rather than the expected content. Fix this by adding `await page.wait(timeout_ms=5000)` **before the first action that failed**. If the existing code already has a `page.wait()` before that action and it still failed, increase the timeout (e.g., 5000→8000→10000→15000).
+When the error or page text suggests the page wasn't ready for interaction, the script acted too soon. Signs include: blank page messages, "still on X page", loading spinners/overlays, progress indicators, or the page text showing a transitional state rather than the expected content.
+
+**Where to place `page.wait()`** depends on WHY the page wasn't ready:
+
+1. **After `page.goto()` / navigation** — If the error is "blank page", "page not loaded", or the page text is empty/minimal after navigating to a URL, the page hasn't finished rendering. Add `await page.wait(timeout_ms=5000)` **after** the `page.goto()` call, before the next interaction:
+ ```python
+ await page.goto('https://example.com/login')
+ await page.wait(timeout_ms=5000) # wait for JS-heavy page to render
+ await page.fill(selector='#username', value=..., ai='fallback', prompt='...')
+ ```
+
+2. **Before an interaction** — If the page has loaded but a specific element isn't ready yet (loading spinner, overlay, lazy-loaded section), add `await page.wait(timeout_ms=5000)` **before** the action that failed:
+ ```python
+ await page.wait(timeout_ms=5000) # wait for element to appear
+ await page.click(selector='button:has-text("Submit")', ai='fallback', prompt='...')
+ ```
+
+If the existing code already has a `page.wait()` and it still failed, increase the timeout (e.g., 5000→8000→10000→15000).
## What to do
diff --git a/skyvern/forge/prompts/skyvern/script-reviewer-form-filling.j2 b/skyvern/forge/prompts/skyvern/script-reviewer-form-filling.j2
index 33d544ac2..02546c6ed 100644
--- a/skyvern/forge/prompts/skyvern/script-reviewer-form-filling.j2
+++ b/skyvern/forge/prompts/skyvern/script-reviewer-form-filling.j2
@@ -124,7 +124,24 @@ Do NOT add FIELD_MAP entries for any of these standard categories — they are m
Only add FIELD_MAP entries for truly **custom/company-specific** fields that don't fit any standard category above.
## Slow Page Load / Page Not Ready
-When the error or page text suggests the page wasn't ready for interaction, the script acted too soon. Signs include: blank page messages, "still on X page", loading spinners/overlays, progress indicators, or the page text showing a transitional state rather than the expected content. Fix this by adding `await page.wait(timeout_ms=5000)` **before the first action that failed**. If the existing code already has a `page.wait()` before that action and it still failed, increase the timeout (e.g., 5000→8000→10000→15000).
+When the error or page text suggests the page wasn't ready for interaction, the script acted too soon. Signs include: blank page messages, "still on X page", loading spinners/overlays, progress indicators, or the page text showing a transitional state rather than the expected content.
+
+**Where to place `page.wait()`** depends on WHY the page wasn't ready:
+
+1. **After `page.goto()` / navigation** — If the error is "blank page", "page not loaded", or the page text is empty/minimal after navigating to a URL, the page hasn't finished rendering. Add `await page.wait(timeout_ms=5000)` **after** the `page.goto()` call, before the next interaction:
+ ```python
+ await page.goto('https://example.com/login')
+ await page.wait(timeout_ms=5000) # wait for JS-heavy page to render
+ await page.fill(selector='#username', value=..., ai='fallback', prompt='...')
+ ```
+
+2. **Before an interaction** — If the page has loaded but a specific element isn't ready yet (loading spinner, overlay, lazy-loaded section), add `await page.wait(timeout_ms=5000)` **before** the action that failed:
+ ```python
+ await page.wait(timeout_ms=5000) # wait for element to appear
+ await page.click(selector='button:has-text("Submit")', ai='fallback', prompt='...')
+ ```
+
+If the existing code already has a `page.wait()` and it still failed, increase the timeout (e.g., 5000→8000→10000→15000).
## What to do
1. Compare the episode's form fields to the existing FIELD_MAP.
diff --git a/skyvern/forge/prompts/skyvern/script-reviewer.j2 b/skyvern/forge/prompts/skyvern/script-reviewer.j2
index d626b6574..b2b973fce 100644
--- a/skyvern/forge/prompts/skyvern/script-reviewer.j2
+++ b/skyvern/forge/prompts/skyvern/script-reviewer.j2
@@ -124,7 +124,24 @@ The user has provided the following instructions for fixing this script. Priorit
{% endif %}
## Slow Page Load / Page Not Ready
-When the error or page text suggests the page wasn't ready for interaction, the script acted too soon. Signs include: blank page messages, "still on X page", loading spinners/overlays, progress indicators, or the page text showing a transitional state rather than the expected content. Fix this by adding `await page.wait(timeout_ms=5000)` **before the first action that failed**. If the existing code already has a `page.wait()` before that action and it still failed, increase the timeout (e.g., 5000→8000→10000→15000).
+When the error or page text suggests the page wasn't ready for interaction, the script acted too soon. Signs include: blank page messages, "still on X page", loading spinners/overlays, progress indicators, or the page text showing a transitional state rather than the expected content.
+
+**Where to place `page.wait()`** depends on WHY the page wasn't ready:
+
+1. **After `page.goto()` / navigation** — If the error is "blank page", "page not loaded", or the page text is empty/minimal after navigating to a URL, the page hasn't finished rendering. Add `await page.wait(timeout_ms=5000)` **after** the `page.goto()` call, before the next interaction:
+ ```python
+ await page.goto('https://example.com/login')
+ await page.wait(timeout_ms=5000) # wait for JS-heavy page to render
+ await page.fill(selector='#username', value=..., ai='fallback', prompt='...')
+ ```
+
+2. **Before an interaction** — If the page has loaded but a specific element isn't ready yet (loading spinner, overlay, lazy-loaded section), add `await page.wait(timeout_ms=5000)` **before** the action that failed:
+ ```python
+ await page.wait(timeout_ms=5000) # wait for element to appear
+ await page.click(selector='button:has-text("Submit")', ai='fallback', prompt='...')
+ ```
+
+If the existing code already has a `page.wait()` and it still failed, increase the timeout (e.g., 5000→8000→10000→15000).
## What to do