Skip to content

fix(scraper): fall back to browser on tls certificate errors#378

Merged
arabold merged 1 commit intomainfrom
fix/368-tls-browser-fallback
Mar 29, 2026
Merged

fix(scraper): fall back to browser on tls certificate errors#378
arabold merged 1 commit intomainfrom
fix/368-tls-browser-fallback

Conversation

@arabold
Copy link
Copy Markdown
Owner

@arabold arabold commented Mar 29, 2026

Summary

  • classify TLS certificate validation failures as non-retryable scraper transport errors
  • fall back to the browser fetcher when the HTTP fetcher cannot build a certificate trust chain
  • add regression tests for both TLS non-retry behavior and browser fallback handling

Testing

  • npx vitest run src/scraper/fetcher/HttpFetcher.test.ts src/scraper/fetcher/AutoDetectFetcher.test.ts
  • npx tsc --noEmit --pretty false
  • npx biome check src/scraper/fetcher/AutoDetectFetcher.ts src/scraper/fetcher/AutoDetectFetcher.test.ts src/scraper/fetcher/HttpFetcher.ts src/scraper/fetcher/HttpFetcher.test.ts src/utils/errors.ts

Fixes #368.

Follow-up security configuration work is tracked separately in #376.

Treat TLS certificate validation failures as non-retryable and fall back to the browser fetcher when the HTTP client cannot build a trust chain. This keeps broken third-party certificate chains from failing after repeated backoff attempts while preserving stricter transport checks by default.

Refs #368
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves scraper resilience to TLS certificate validation failures by classifying them as non-retryable errors and routing affected requests through the browser-based fetcher as a fallback.

Changes:

  • Introduces TlsCertificateError to represent certificate validation failures as non-retryable ScraperErrors.
  • Updates HttpFetcher to detect common TLS certificate error codes, avoid retries, and throw TlsCertificateError.
  • Updates AutoDetectFetcher to fall back to BrowserFetcher on TlsCertificateError, with regression tests for both behaviors.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/utils/errors.ts Adds TlsCertificateError as a dedicated non-retryable scraper error type.
src/scraper/fetcher/HttpFetcher.ts Detects TLS certificate error codes and throws TlsCertificateError without retrying.
src/scraper/fetcher/HttpFetcher.test.ts Adds a regression test ensuring TLS certificate failures do not trigger retries.
src/scraper/fetcher/AutoDetectFetcher.ts Falls back to BrowserFetcher when HttpFetcher throws TlsCertificateError.
src/scraper/fetcher/AutoDetectFetcher.test.ts Adds tests for TLS fallback, challenge fallback, and non-fallback error behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@arabold arabold merged commit 37e72a0 into main Mar 29, 2026
7 checks passed
@arabold arabold deleted the fix/368-tls-browser-fallback branch March 29, 2026 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Failed to fetch - unable to verify the first certificate

2 participants