Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,32 @@ async function launchChromeBrowser() {
});
}

function isTransientNavigationError(err) {
const message = err && (err.stack || err.message) ? String(err.stack || err.message) : String(err);
return [
'net::ERR_NETWORK_CHANGED',
'net::ERR_NETWORK_RESET',
'net::ERR_TIMED_OUT',
].some((needle) => message.includes(needle));
}
Comment thread
intel352 marked this conversation as resolved.

async function gotoWithTransientRetry(page, url, timeout) {
let lastErr;
for (let attempt = 1; attempt <= 3; attempt++) {
try {
await page.goto(url, { waitUntil: 'domcontentloaded', timeout });
return;
} catch (err) {
lastErr = err;
if (attempt === 3 || !isTransientNavigationError(err)) {
throw err;
}
await page.waitForTimeout(500 * attempt);
}
}
throw lastErr;
}

async function main() {
const url = process.argv[2];
const timeout = Number(process.argv[3] || 45000);
Expand All @@ -441,7 +467,7 @@ async function main() {
Object.defineProperty(navigator, 'webdriver', { get: () => undefined });
});
try {
await page.goto(url, { waitUntil: 'domcontentloaded', timeout });
await gotoWithTransientRetry(page, url, timeout);
if (await page.locator('form[action*="/errors/validateCaptcha"]').count()) {
throw new Error('amazon interstitial requires manual review');
}
Expand Down
21 changes: 21 additions & 0 deletions internal/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,27 @@ func TestPlaywrightScriptWaitsForCaptureRelevantNodes(t *testing.T) {
}
}

func TestPlaywrightScriptRetriesTransientNavigationFailures(t *testing.T) {
for _, required := range []string{
"isTransientNavigationError",
"net::ERR_NETWORK_CHANGED",
"net::ERR_NETWORK_RESET",
"net::ERR_TIMED_OUT",
"for (let attempt = 1; attempt <= 3; attempt++)",
"await page.goto(url, { waitUntil: 'domcontentloaded', timeout });",
"String(err)",
} {
if !strings.Contains(playwrightCaptureScript, required) {
t.Fatalf("playwright script must retry transient navigation failure path %q", required)
}
}
retryIndex := strings.Index(playwrightCaptureScript, "await gotoWithTransientRetry(page, url, timeout);")
captchaIndex := strings.Index(playwrightCaptureScript, `form[action*="/errors/validateCaptcha"]`)
if retryIndex < 0 || captchaIndex < 0 || captchaIndex < retryIndex {
t.Fatal("playwright script must check CAPTCHA/interstitials after retryable navigation only")
}
}

func containsString(values []string, want string) bool {
for _, value := range values {
if value == want {
Expand Down