The public interface for all rate-limiting strategies. Library consumers are welcome to provide their own implementations of this interface in the Scraper constructor options.

The RateLimitEvent object contains both the request and response information associated with the event.

import { Scraper, RateLimitStrategy } from "@the-convocation/twitter-scraper";

// A custom rate-limiting implementation that just logs request/response information.
class ConsoleLogRateLimitStrategy implements RateLimitStrategy {
async onRateLimit(event: RateLimitEvent): Promise<void> {
console.log(event.fetchParameters, event.response);
}
}

const scraper = new Scraper({
rateLimitStrategy: new ConsoleLogRateLimitStrategy(),
});
interface RateLimitStrategy {
    onRateLimit(event: RateLimitEvent): Promise<void>;
}

Implemented by

Methods

Methods