Custom Strategy Sets
Waterfall-Fetch allows you to customize the order and selection of strategies used to fetch HTML content. This advanced feature gives you fine-grained control over the fetching process, allowing you to optimize for your specific use case.Built-in Strategy Sets
By default, Waterfall-Fetch comes with two built-in strategy sets:-
Cheap Set: Optimized for cost-effectiveness and speed
- Axios
- Node-fetch
- Puppeteer (as a last resort)
-
JS Set: Designed for JavaScript-heavy websites (slower, but more accurate)
- Puppeteer (with stealth mode)
- Axios (as a fallback)
- Node-fetch (as a final attempt)
Using Built-in Sets
To use a built-in set, you can specify it in theoptions
parameter of the getHtml
function:
Custom Strategy Sets
You can create your own custom strategy set by passing an array of strategy functions to theset
option. This allows you to prioritize strategies based on your specific needs.
To create a custom set:
- Import the strategy functions you want to use
- Create an array with your desired order of strategies
- Pass this array to the
set
option
Strategy Order and Fallback Behavior
The order of strategies in your custom set is crucial:- Strategies are attempted in the order they appear in the array.
- If a strategy fails, Waterfall-Fetch moves to the next strategy in the array.
- If all strategies fail, Waterfall-Fetch will throw an error.
- You can include the same strategy multiple times in the array, which can be useful for retrying a strategy with different options or configurations.