Add Cloudflare Puppeteer scraper + Tavily fallback for article extraction#39
Merged
Merged
Conversation
…traction with 8s bound + Tavily fallback
Wire the deployed Cloudflare Puppeteer scraper (proxy.qwksearch.com) into the
qwksearch-web /api/doc/article extraction path so JavaScript-heavy and lightly
bot-protected pages render before readability extraction.
Fresh extraction now uses a bounded fallback chain:
1. Cloudflare Puppeteer scraper, 8s deadline (renders + readability)
2. Tavily extract API (when the scraper times out or returns a challenge page)
3. In-process ai-research-agent extraction (last resort)
- lib/scraper/scrape-url.ts: new extractArticleViaScraper (8s AbortController
deadline, challenge-page detection, citation/word-count enrichment) and
extractViaTavily fallback.
- cloudflare-scraper-client.ts: default to proxy.qwksearch.com and call the
worker over GET with query params (the deployed worker rejects POST with
error 1101); add AbortSignal support to bound requests.
- api/doc/article/route.ts: primary scraper -> Tavily -> extractContent chain,
each tier returning {error} instead of throwing.
- extract-webpage url-to-html.ts: point scrapeCloudflare at proxy.qwksearch.com
over GET for consistency.
- Tests: mock the scraper + Tavily helpers; add scraper-success and
Tavily-fallback cases.
Verified end-to-end: Wikipedia articles extract via the scraper in 3-5s
(1394 and 1895 words); heavily-protected AP News aborts at the 8s deadline and
advances to the Tavily fallback.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PZnQTSy6fHh8Y6naPkxYrC
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
qwksearch | 8337c45 | Commit Preview URL Branch Preview URL |
Jul 06 2026, 09:42 AM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements a bounded fallback chain for article extraction that prioritizes JavaScript-aware rendering over plain HTTP fetching. The new extraction pipeline uses the Cloudflare Puppeteer scraper (8s deadline) as the primary path, falls back to Tavily extract API when the scraper times out or returns challenge pages, and finally falls back to direct in-process extraction as a last resort.
Key Changes
New
scrape-url.tsmodule: Provides two main extraction functions:extractArticleViaScraper(): Renders URLs through the Cloudflare Puppeteer scraper worker with an 8-second deadline, detects bot-challenge interstitials (Cloudflare, Datadome, AP News), and extracts content via readability. Never throws—returns{ error }on failure.extractViaTavily(): Fallback extraction via Tavily's extract API when the scraper is unavailable or times out. Converts Tavily's markdown-likeraw_contentto HTML and builds APA-style citations.Updated
/api/doc/articleroute: Implements the three-tier extraction fallback:extractContent()(last resort)Each tier logs its decision and reason for advancing to the next tier, enabling observability of which extraction path succeeds.
Updated scraper client configuration: Changed default scraper endpoint from
https://scraper.qwksearch.workers.devtohttps://proxy.qwksearch.comand addedAbortSignalsupport for deadline enforcement.Updated
url-to-html.ts: Migrated scraper requests from POST with JSON body to GET with query-string parameters to match the deployed worker's API.Enhanced test coverage: Added tests for scraper and Tavily extraction paths, with mocks that default to "unavailable" so existing tests exercise the
extractContentfallback.Notable Implementation Details
{ error }instead of throwing, allowing the route to cleanly decide whether to advance to the next tier without try-catch complexity.https://claude.ai/code/session_01PZnQTSy6fHh8Y6naPkxYrC