@the-convocation/twitter-scraper 0.18.3 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,54 @@
1
+ # CycleTLS Cloudflare Bypass Example
2
+
3
+ This example demonstrates how to use the `@the-convocation/twitter-scraper/cycletls` entrypoint to bypass Cloudflare bot detection when authenticating with Twitter.
4
+
5
+ ## Problem
6
+
7
+ Twitter's authentication endpoints may be protected by Cloudflare's advanced bot detection, which analyzes TLS fingerprints to detect non-browser clients. Standard Node.js TLS handshakes can trigger `403 Forbidden` errors during login.
8
+
9
+ ## Solution
10
+
11
+ This example uses [CycleTLS](https://github.com/Danny-Dasilva/CycleTLS), which leverages golang to mimic Chrome browser TLS fingerprints, allowing requests to pass through Cloudflare's protection.
12
+
13
+ ## Installation
14
+
15
+ ```sh
16
+ yarn install
17
+ ```
18
+
19
+ ## Configuration
20
+
21
+ Create a `.env` file in the root of the repository (two levels up) with your Twitter credentials:
22
+
23
+ ```
24
+ TWITTER_USERNAME=your_username
25
+ TWITTER_PASSWORD=your_password
26
+ TWITTER_EMAIL=your_email
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ```sh
32
+ yarn start
33
+ ```
34
+
35
+ ## How it works
36
+
37
+ The example imports the `cycleTLSFetch` function from the `/cycletls` subpath:
38
+
39
+ ```ts
40
+ import { Scraper } from '@the-convocation/twitter-scraper';
41
+ import { cycleTLSFetch, cycleTLSExit } from '@the-convocation/twitter-scraper/cycletls';
42
+
43
+ const scraper = new Scraper({
44
+ fetch: cycleTLSFetch as any,
45
+ });
46
+ ```
47
+
48
+ This replaces the default fetch implementation with one that uses Chrome-like TLS fingerprints, bypassing Cloudflare's detection.
49
+
50
+ ## Important Notes
51
+
52
+ - **Node.js only**: The `/cycletls` entrypoint requires Node.js and will not work in browsers
53
+ - **Cleanup required**: Always call `cycleTLSExit()` when done to cleanup golang resources
54
+ - **Optional dependency**: `cycletls` must be explicitly installed alongside the main package
@@ -0,0 +1,12 @@
1
+ {
2
+ "private": true,
3
+ "packageManager": "yarn@1.22.19",
4
+ "scripts": {
5
+ "start": "tsx src/index.ts"
6
+ },
7
+ "dependencies": {
8
+ "@the-convocation/twitter-scraper": "file:../../",
9
+ "cycletls": "^2.0.4",
10
+ "tsx": "^4.15.5"
11
+ }
12
+ }
package/package.json CHANGED
@@ -7,18 +7,25 @@
7
7
  "scraper",
8
8
  "crawler"
9
9
  ],
10
- "version": "0.18.3",
10
+ "version": "0.19.0",
11
11
  "main": "dist/default/cjs/index.js",
12
12
  "types": "./dist/types/index.d.ts",
13
13
  "exports": {
14
- "types": "./dist/types/index.d.ts",
15
- "node": {
16
- "import": "./dist/node/esm/index.mjs",
17
- "require": "./dist/node/cjs/index.cjs"
14
+ ".": {
15
+ "types": "./dist/types/index.d.ts",
16
+ "node": {
17
+ "import": "./dist/node/esm/index.mjs",
18
+ "require": "./dist/node/cjs/index.cjs"
19
+ },
20
+ "default": {
21
+ "import": "./dist/default/esm/index.mjs",
22
+ "require": "./dist/default/cjs/index.js"
23
+ }
18
24
  },
19
- "default": {
20
- "import": "./dist/default/esm/index.mjs",
21
- "require": "./dist/default/cjs/index.js"
25
+ "./cycletls": {
26
+ "types": "./dist/cycletls/index.d.ts",
27
+ "import": "./dist/cycletls/esm/index.mjs",
28
+ "require": "./dist/cycletls/cjs/index.cjs"
22
29
  }
23
30
  },
24
31
  "repository": "https://github.com/the-convocation/twitter-scraper.git",
@@ -33,7 +40,7 @@
33
40
  "commit": "cz",
34
41
  "docs:generate": "typedoc --options typedoc.json",
35
42
  "docs:deploy": "yarn docs:generate && gh-pages -d docs",
36
- "format": "prettier --write src/**/*.ts",
43
+ "format": "prettier --write src/**/*.ts examples/**/*.{ts,js,tsx}",
37
44
  "prepare": "husky install",
38
45
  "test": "jest"
39
46
  },
@@ -48,6 +55,14 @@
48
55
  "tough-cookie": "^4.1.2",
49
56
  "tslib": "^2.5.2"
50
57
  },
58
+ "peerDependencies": {
59
+ "cycletls": "^2.0.4"
60
+ },
61
+ "peerDependenciesMeta": {
62
+ "cycletls": {
63
+ "optional": true
64
+ }
65
+ },
51
66
  "devDependencies": {
52
67
  "@commitlint/cli": "^17.6.3",
53
68
  "@commitlint/config-conventional": "^17.6.3",
@@ -59,6 +74,7 @@
59
74
  "@types/tough-cookie": "^4.0.2",
60
75
  "@typescript-eslint/eslint-plugin": "^5.59.7",
61
76
  "@typescript-eslint/parser": "^5.59.7",
77
+ "cycletls": "^2.0.4",
62
78
  "cz-conventional-changelog": "^3.3.0",
63
79
  "dotenv": "^16.3.1",
64
80
  "esbuild": "^0.21.5",
package/rollup.config.mjs CHANGED
@@ -58,4 +58,38 @@ export default [
58
58
  format: 'es',
59
59
  },
60
60
  },
61
+ // CycleTLS build (Node-only)
62
+ {
63
+ input: 'src/_cycletls.ts',
64
+ external: ['cycletls'],
65
+ plugins: [
66
+ esbuild({
67
+ define: {
68
+ PLATFORM_NODE: 'true',
69
+ PLATFORM_NODE_JEST: 'false',
70
+ },
71
+ }),
72
+ ],
73
+ output: [
74
+ {
75
+ file: 'dist/cycletls/cjs/index.cjs',
76
+ format: 'cjs',
77
+ sourcemap: true,
78
+ },
79
+ {
80
+ file: 'dist/cycletls/esm/index.mjs',
81
+ format: 'es',
82
+ sourcemap: true,
83
+ },
84
+ ],
85
+ },
86
+ {
87
+ input: 'src/_cycletls.ts',
88
+ external: ['cycletls'],
89
+ plugins: [dts()],
90
+ output: {
91
+ file: 'dist/cycletls/index.d.ts',
92
+ format: 'es',
93
+ },
94
+ },
61
95
  ];