This example demonstrates how to use the @the-convocation/twitter-scraper/cycletls entrypoint to bypass Cloudflare bot detection when authenticating with Twitter.
Twitter's authentication endpoints may be protected by Cloudflare's bot detection, which analyzes TLS fingerprints to detect non-browser clients. Standard Node.js TLS handshakes can trigger 403 Forbidden errors during login.
This example uses CycleTLS to mimic Chrome browser TLS fingerprints, allowing requests to pass through Cloudflare's protection.
yarn installCreate a .env file in this directory with your Twitter credentials:
TWITTER_USERNAME=your_username
TWITTER_PASSWORD=your_password
TWITTER_EMAIL=your_email
yarn startThe example imports the cycleTLSFetch function from the /cycletls subpath:
import { Scraper } from '@the-convocation/twitter-scraper';
import { cycleTLSFetch, cycleTLSExit } from '@the-convocation/twitter-scraper/cycletls';
const scraper = new Scraper({
fetch: cycleTLSFetch,
});This replaces the default fetch implementation with one that uses Chrome-like TLS fingerprints, bypassing Cloudflare's detection.