Learn how to create and use custom fetching strategies
FetchStrategyFunction
type FetchStrategyFunction = (url: string, evalFunction?: OnPageEvaluationFunction) => Promise<StrategyResponse>;
import axios from "axios"; async function customAxiosStrategy(url: string): Promise<StrategyResponse> { const strategy = { name: "custom-axios", cost: 0 }; try { const response = await axios.get(url, { headers: { "User-Agent": "Custom User Agent", // Add other custom headers here }, }); return { success: true, strategy, html: response.data, error: null, status: response.status, }; } catch (error) { return { success: false, strategy, html: null, error, status: error.response?.status || null, }; } }
set
getHtml
import getHtml, { fetchWithNodeFetch, fetchWithStealthPuppeteer } from "waterfall-fetch"; const url = "https://example.com"; const customSet = [customAxiosStrategy, fetchWithNodeFetch, fetchWithStealthPuppeteer]; const result = await getHtml(url, { set: customSet });