@detiq/crawler 1.1.8 → 1.1.9

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.
Files changed (82) hide show
  1. package/dist/accessibility-auditor.js +74 -54
  2. package/dist/ai-login.js +249 -227
  3. package/dist/auth-token-rotator.js +67 -57
  4. package/dist/auth.js +336 -299
  5. package/dist/browser-extension.js +142 -104
  6. package/dist/captcha-solver.js +125 -98
  7. package/dist/color-contrast.js +89 -77
  8. package/dist/content-chunker.js +126 -126
  9. package/dist/content-dedup.js +71 -54
  10. package/dist/cookie-consent.js +83 -68
  11. package/dist/cookie-jar.js +60 -53
  12. package/dist/crawler.js +5345 -4486
  13. package/dist/custom-js-injector.js +61 -45
  14. package/dist/dark-mode-capture.js +81 -67
  15. package/dist/dead-link-detector.js +55 -47
  16. package/dist/element-hash.js +12 -8
  17. package/dist/email-otp.js +195 -154
  18. package/dist/engine-router.js +98 -87
  19. package/dist/export/bulk-export.js +55 -70
  20. package/dist/export/vector-export.js +105 -77
  21. package/dist/extractors/advanced.js +266 -249
  22. package/dist/extractors/artifact-envelope.js +58 -59
  23. package/dist/failure-analysis-agent.js +33 -37
  24. package/dist/feature-flag-detector.js +66 -51
  25. package/dist/form-detector.js +75 -55
  26. package/dist/frontier.js +101 -76
  27. package/dist/gap-pass.js +89 -68
  28. package/dist/graphql-detector.js +72 -62
  29. package/dist/http-engine.js +330 -282
  30. package/dist/incremental-diff.js +87 -54
  31. package/dist/index.js +28 -67
  32. package/dist/input-fuzzer.js +97 -93
  33. package/dist/interactive-probe.js +827 -715
  34. package/dist/job-queue.js +2169 -2151
  35. package/dist/js-coverage.js +56 -52
  36. package/dist/js-router-detector.js +117 -86
  37. package/dist/language-detector.js +63 -51
  38. package/dist/link-classifier.js +50 -32
  39. package/dist/live-view.js +108 -91
  40. package/dist/locator-extractor.js +187 -151
  41. package/dist/logger.js +7 -9
  42. package/dist/markdown-extract.js +61 -48
  43. package/dist/native-crawler.js +946 -780
  44. package/dist/network-observer.js +156 -135
  45. package/dist/network-throttle.js +40 -29
  46. package/dist/openapi-generator.js +92 -77
  47. package/dist/pdf-extractor.js +90 -72
  48. package/dist/performance-metrics.js +102 -80
  49. package/dist/phash.js +144 -125
  50. package/dist/pii-scrubber.js +68 -65
  51. package/dist/playwright-recorder.js +58 -70
  52. package/dist/policies/crawl-safety.js +34 -31
  53. package/dist/profiles/domain-profile.js +125 -130
  54. package/dist/proxy.js +172 -146
  55. package/dist/rate-limiter.js +65 -58
  56. package/dist/redirect-tracker.js +64 -60
  57. package/dist/redis-frontier.js +136 -116
  58. package/dist/redis-queue.js +144 -157
  59. package/dist/response-cache.js +140 -127
  60. package/dist/responsive-detector.js +46 -42
  61. package/dist/retry-policy.js +50 -46
  62. package/dist/robots-txt.js +83 -69
  63. package/dist/screen-reader.js +70 -45
  64. package/dist/screenshot-masker.js +77 -59
  65. package/dist/seo-checker.js +107 -88
  66. package/dist/session-capture.js +212 -192
  67. package/dist/session-export.js +133 -107
  68. package/dist/sitemap-writer.js +41 -38
  69. package/dist/sitemap.js +202 -141
  70. package/dist/skyvern.js +148 -123
  71. package/dist/sqs-queue.js +42 -42
  72. package/dist/sso-token.js +90 -74
  73. package/dist/stealth/human-behavior.js +173 -156
  74. package/dist/telemetry.js +82 -68
  75. package/dist/test-executor.js +335 -309
  76. package/dist/tls-fingerprint.js +88 -77
  77. package/dist/url-pattern-completer.js +90 -71
  78. package/dist/visual-diff-verdict.js +38 -23
  79. package/dist/webhook-notifier.js +69 -71
  80. package/dist/websocket-detector.js +68 -56
  81. package/dist/worker.js +38 -29
  82. package/package.json +1 -1
@@ -1,113 +1,151 @@
1
- import { createHash, randomBytes } from "node:crypto";
2
- import { createWriteStream, existsSync, mkdirSync } from "node:fs";
3
- import { writeFile, mkdir, rm } from "node:fs/promises";
4
- import { join } from "node:path";
5
- import { tmpdir } from "node:os";
6
- import { pipeline } from "node:stream/promises";
7
- import { Readable } from "node:stream";
8
- const PROFILE_BASE = process.env.EXTENSION_PROFILE_DIR ?? join(tmpdir(), "zeta-ext-profiles");
1
+ /**
2
+ * Browser extension injection support.
3
+ *
4
+ * Chrome extensions require a persistent profile directory — incompatible
5
+ * with headless Docker by default. This module handles:
6
+ * 1. Persistent profile directory per extension set
7
+ * 2. Extension download from .crx URL or load from local path
8
+ * 3. Launch args for Playwright / Stagehand
9
+ *
10
+ * Usage:
11
+ * const profile = await prepareExtensionProfile(['/path/to/ext.crx']);
12
+ * // pass profile.userDataDir and profile.args to browser launch
13
+ */
14
+ import { createHash, randomBytes } from 'node:crypto';
15
+ import { createWriteStream, existsSync, mkdirSync } from 'node:fs';
16
+ import { writeFile, mkdir, rm } from 'node:fs/promises';
17
+ import { join } from 'node:path';
18
+ import { tmpdir } from 'node:os';
19
+ import { pipeline } from 'node:stream/promises';
20
+ import { Readable } from 'node:stream';
21
+ const PROFILE_BASE = process.env.EXTENSION_PROFILE_DIR ?? join(tmpdir(), 'zeta-ext-profiles');
22
+ /**
23
+ * Download a .crx from a URL to a temp file. Returns path.
24
+ */
9
25
  async function downloadCrx(url) {
10
- const dest = join(tmpdir(), `zeta-ext-${randomBytes(6).toString("hex")}.crx`);
11
- const res = await fetch(url);
12
- if (!res.ok) throw new Error(`Failed to download extension from ${url}: ${res.status}`);
13
- const writer = createWriteStream(dest);
14
- await pipeline(Readable.fromWeb(res.body), writer);
15
- return dest;
26
+ const dest = join(tmpdir(), `zeta-ext-${randomBytes(6).toString('hex')}.crx`);
27
+ const res = await fetch(url);
28
+ if (!res.ok)
29
+ throw new Error(`Failed to download extension from ${url}: ${res.status}`);
30
+ const writer = createWriteStream(dest);
31
+ await pipeline(Readable.fromWeb(res.body), writer);
32
+ return dest;
16
33
  }
34
+ /**
35
+ * Unpack a .crx file to a directory Chrome can load as an unpacked extension.
36
+ * CRX3 format: 4-byte magic + 4-byte version + 4-byte header_size + proto header + zip body
37
+ */
17
38
  async function unpackCrx(crxPath, destDir) {
18
- const { readFile } = await import("node:fs/promises");
19
- const buf = await readFile(crxPath);
20
- const magic = buf.readUInt32LE(0);
21
- if (magic !== 1131557428) {
39
+ const { readFile } = await import('node:fs/promises');
40
+ const buf = await readFile(crxPath);
41
+ const magic = buf.readUInt32LE(0);
42
+ if (magic !== 0x43723234) {
43
+ // Not CRX — assume it's already a zip (unpacked extension)
44
+ await mkdir(destDir, { recursive: true });
45
+ await writeFile(join(destDir, '__raw.crx'), buf);
46
+ return;
47
+ }
48
+ const version = buf.readUInt32LE(4);
49
+ let zipStart;
50
+ if (version === 3) {
51
+ const headerSize = buf.readUInt32LE(8);
52
+ zipStart = 12 + headerSize;
53
+ }
54
+ else if (version === 2) {
55
+ const pubKeyLen = buf.readUInt32LE(8);
56
+ const sigLen = buf.readUInt32LE(12);
57
+ zipStart = 16 + pubKeyLen + sigLen;
58
+ }
59
+ else {
60
+ throw new Error(`Unknown CRX version ${version}`);
61
+ }
62
+ const zipBuf = buf.subarray(zipStart);
63
+ const tmpZip = join(tmpdir(), `zeta-ext-${randomBytes(4).toString('hex')}.zip`);
64
+ await writeFile(tmpZip, zipBuf);
22
65
  await mkdir(destDir, { recursive: true });
23
- await writeFile(join(destDir, "__raw.crx"), buf);
24
- return;
25
- }
26
- const version = buf.readUInt32LE(4);
27
- let zipStart;
28
- if (version === 3) {
29
- const headerSize = buf.readUInt32LE(8);
30
- zipStart = 12 + headerSize;
31
- } else if (version === 2) {
32
- const pubKeyLen = buf.readUInt32LE(8);
33
- const sigLen = buf.readUInt32LE(12);
34
- zipStart = 16 + pubKeyLen + sigLen;
35
- } else {
36
- throw new Error(`Unknown CRX version ${version}`);
37
- }
38
- const zipBuf = buf.subarray(zipStart);
39
- const tmpZip = join(tmpdir(), `zeta-ext-${randomBytes(4).toString("hex")}.zip`);
40
- await writeFile(tmpZip, zipBuf);
41
- await mkdir(destDir, { recursive: true });
42
- const unzipper = await import("unzipper").catch(() => null);
43
- if (unzipper) {
44
- await unzipper.Open.file(tmpZip).then((d) => d.extract({ path: destDir }));
45
- } else {
46
- const { execFile } = await import("node:child_process");
47
- await new Promise(
48
- (res, rej) => execFile("unzip", ["-o", tmpZip, "-d", destDir], (err) => err ? rej(err) : res())
49
- );
50
- }
51
- await rm(tmpZip, { force: true });
66
+ // Extract using unzipper (available in Node without native deps)
67
+ // @ts-ignore – no types for unzipper
68
+ const unzipper = await import('unzipper').catch(() => null);
69
+ if (unzipper) {
70
+ await unzipper.Open.file(tmpZip).then((d) => d.extract({ path: destDir }));
71
+ }
72
+ else {
73
+ // Fallback: shell unzip
74
+ const { execFile } = await import('node:child_process');
75
+ await new Promise((res, rej) => execFile('unzip', ['-o', tmpZip, '-d', destDir], (err) => err ? rej(err) : res()));
76
+ }
77
+ await rm(tmpZip, { force: true });
52
78
  }
53
- async function prepareExtensionProfile(extensions) {
54
- const key = createHash("md5").update(extensions.map((e) => e.source).sort().join("|")).digest("hex").slice(0, 12);
55
- const profileDir = join(PROFILE_BASE, key);
56
- const extensionDirs = [];
57
- mkdirSync(profileDir, { recursive: true });
58
- for (const ext of extensions) {
59
- const extHash = createHash("md5").update(ext.source).digest("hex").slice(0, 8);
60
- const extDir = join(profileDir, `ext-${extHash}`);
61
- if (!existsSync(extDir)) {
62
- let crxPath = ext.source;
63
- if (ext.source.startsWith("http://") || ext.source.startsWith("https://")) {
64
- crxPath = await downloadCrx(ext.source);
65
- await unpackCrx(crxPath, extDir);
66
- await rm(crxPath, { force: true });
67
- } else if (ext.source.endsWith(".crx")) {
68
- await unpackCrx(ext.source, extDir);
69
- } else {
70
- extensionDirs.push(ext.source);
71
- continue;
72
- }
79
+ /**
80
+ * Prepare a Chrome user-data-dir with the given extensions loaded.
81
+ * Returns profile info + cleanup function.
82
+ */
83
+ export async function prepareExtensionProfile(extensions) {
84
+ // Stable profile key based on extension sources
85
+ const key = createHash('md5')
86
+ .update(extensions.map(e => e.source).sort().join('|'))
87
+ .digest('hex')
88
+ .slice(0, 12);
89
+ const profileDir = join(PROFILE_BASE, key);
90
+ const extensionDirs = [];
91
+ mkdirSync(profileDir, { recursive: true });
92
+ for (const ext of extensions) {
93
+ const extHash = createHash('md5').update(ext.source).digest('hex').slice(0, 8);
94
+ const extDir = join(profileDir, `ext-${extHash}`);
95
+ if (!existsSync(extDir)) {
96
+ let crxPath = ext.source;
97
+ if (ext.source.startsWith('http://') || ext.source.startsWith('https://')) {
98
+ crxPath = await downloadCrx(ext.source);
99
+ await unpackCrx(crxPath, extDir);
100
+ await rm(crxPath, { force: true });
101
+ }
102
+ else if (ext.source.endsWith('.crx')) {
103
+ await unpackCrx(ext.source, extDir);
104
+ }
105
+ else {
106
+ // Assume already-unpacked extension directory — symlink or copy
107
+ extensionDirs.push(ext.source);
108
+ continue;
109
+ }
110
+ }
111
+ extensionDirs.push(extDir);
73
112
  }
74
- extensionDirs.push(extDir);
75
- }
76
- const userDataDir = join(profileDir, "user-data");
77
- mkdirSync(userDataDir, { recursive: true });
78
- const defaultsDir = join(userDataDir, "Default");
79
- mkdirSync(defaultsDir, { recursive: true });
80
- const prefsPath = join(defaultsDir, "Preferences");
81
- if (!existsSync(prefsPath)) {
82
- await writeFile(prefsPath, JSON.stringify({
83
- browser: { has_seen_welcome_page: true },
84
- extensions: { alerts: { initialized: true } }
85
- }), "utf8");
86
- }
87
- const loadExtensionArg = extensionDirs.join(",");
88
- const args = [
89
- `--load-extension=${loadExtensionArg}`,
90
- `--disable-extensions-except=${loadExtensionArg}`,
91
- `--user-data-dir=${userDataDir}`,
92
- "--no-first-run",
93
- "--no-default-browser-check"
94
- ];
95
- return {
96
- userDataDir,
97
- args,
98
- cleanup: async () => {
99
- await rm(profileDir, { recursive: true, force: true });
113
+ const userDataDir = join(profileDir, 'user-data');
114
+ mkdirSync(userDataDir, { recursive: true });
115
+ // Write a minimal Preferences file so Chrome doesn't show first-run UI
116
+ const defaultsDir = join(userDataDir, 'Default');
117
+ mkdirSync(defaultsDir, { recursive: true });
118
+ const prefsPath = join(defaultsDir, 'Preferences');
119
+ if (!existsSync(prefsPath)) {
120
+ await writeFile(prefsPath, JSON.stringify({
121
+ browser: { has_seen_welcome_page: true },
122
+ extensions: { alerts: { initialized: true } },
123
+ }), 'utf8');
100
124
  }
101
- };
125
+ const loadExtensionArg = extensionDirs.join(',');
126
+ const args = [
127
+ `--load-extension=${loadExtensionArg}`,
128
+ `--disable-extensions-except=${loadExtensionArg}`,
129
+ `--user-data-dir=${userDataDir}`,
130
+ '--no-first-run',
131
+ '--no-default-browser-check',
132
+ ];
133
+ return {
134
+ userDataDir,
135
+ args,
136
+ cleanup: async () => {
137
+ await rm(profileDir, { recursive: true, force: true });
138
+ },
139
+ };
102
140
  }
103
- async function adBlockerProfile() {
104
- return prepareExtensionProfile([{
105
- name: "uBlock Origin",
106
- source: "https://github.com/gorhill/uBlock/releases/download/1.57.2/uBlock0_1.57.2.chromium.zip"
107
- }]);
141
+ /**
142
+ * Ad-blocker extension profile using the uBlock Origin CRX.
143
+ * Reduces noise from ad networks during crawls.
144
+ */
145
+ export async function adBlockerProfile() {
146
+ // uBlock Origin 1.57.2 from GitHub release (MIT licensed)
147
+ return prepareExtensionProfile([{
148
+ name: 'uBlock Origin',
149
+ source: 'https://github.com/gorhill/uBlock/releases/download/1.57.2/uBlock0_1.57.2.chromium.zip',
150
+ }]);
108
151
  }
109
- export {
110
- adBlockerProfile,
111
- prepareExtensionProfile
112
- };
113
- //# sourceMappingURL=browser-extension.js.map
@@ -1,105 +1,132 @@
1
- const POLL_INTERVAL_MS = 3e3;
2
- const MAX_ATTEMPTS = 40;
3
- async function solveCaptcha(page, pageUrl, apiKey, provider = "2captcha") {
4
- const captchaInfo = await page.evaluate(() => {
5
- const recaptchaEl = document.querySelector(".g-recaptcha, [data-sitekey]");
6
- if (recaptchaEl) {
7
- const sitekey = recaptchaEl.getAttribute("data-sitekey") || "";
8
- return { type: "recaptcha", sitekey };
9
- }
10
- const hcaptchaEl = document.querySelector(".h-captcha, [data-hcaptcha-sitekey]");
11
- if (hcaptchaEl) {
12
- const sitekey = hcaptchaEl.getAttribute("data-sitekey") || hcaptchaEl.getAttribute("data-hcaptcha-sitekey") || "";
13
- return { type: "hcaptcha", sitekey };
14
- }
15
- const turnstileEl = document.querySelector(".cf-turnstile");
16
- if (turnstileEl) {
17
- const sitekey = turnstileEl.getAttribute("data-sitekey") || "";
18
- return { type: "turnstile", sitekey };
19
- }
20
- return null;
21
- });
22
- if (!captchaInfo?.sitekey) return null;
23
- const token = provider === "capsolver" ? await solveWithCapSolver(captchaInfo.type, captchaInfo.sitekey, pageUrl, apiKey) : await solveWith2Captcha(captchaInfo.type, captchaInfo.sitekey, pageUrl, apiKey);
24
- await page.evaluate((t, type) => {
25
- if (type === "recaptcha") {
26
- const el = document.querySelector("textarea.g-recaptcha-response");
27
- if (el) {
28
- el.value = t;
29
- }
30
- if (window.grecaptcha?.getResponse && document.querySelector("[data-callback]")) {
31
- const cb = document.querySelector("[data-callback]")?.getAttribute("data-callback");
32
- if (cb && window[cb]) window[cb](t);
33
- }
34
- }
35
- if (type === "hcaptcha") {
36
- const el = document.querySelector('textarea[name="h-captcha-response"]');
37
- if (el) {
38
- el.value = t;
39
- }
40
- }
41
- if (type === "turnstile") {
42
- const el = document.querySelector('[name="cf-turnstile-response"]');
43
- if (el) {
44
- el.value = t;
45
- }
46
- }
47
- }, token, captchaInfo.type);
48
- return { token, provider };
1
+ /**
2
+ * CAPTCHA auto-solving via 2captcha or CapSolver APIs.
3
+ * Supports reCAPTCHA v2, hCaptcha, and Cloudflare Turnstile.
4
+ */
5
+ // Poll interval and max attempts
6
+ const POLL_INTERVAL_MS = 3_000;
7
+ const MAX_ATTEMPTS = 40; // 2 min max
8
+ /**
9
+ * Detect CAPTCHA type and sitekey on the page, then solve it.
10
+ * Returns null if no CAPTCHA found or solver not configured.
11
+ * Throws on solve failure.
12
+ */
13
+ export async function solveCaptcha(page, pageUrl, apiKey, provider = '2captcha') {
14
+ // Detect CAPTCHA type
15
+ const captchaInfo = await page.evaluate(() => {
16
+ // reCAPTCHA v2
17
+ const recaptchaEl = document.querySelector('.g-recaptcha, [data-sitekey]');
18
+ if (recaptchaEl) {
19
+ const sitekey = recaptchaEl.getAttribute('data-sitekey') || '';
20
+ return { type: 'recaptcha', sitekey };
21
+ }
22
+ // hCaptcha
23
+ const hcaptchaEl = document.querySelector('.h-captcha, [data-hcaptcha-sitekey]');
24
+ if (hcaptchaEl) {
25
+ const sitekey = hcaptchaEl.getAttribute('data-sitekey') || hcaptchaEl.getAttribute('data-hcaptcha-sitekey') || '';
26
+ return { type: 'hcaptcha', sitekey };
27
+ }
28
+ // Cloudflare Turnstile
29
+ const turnstileEl = document.querySelector('.cf-turnstile');
30
+ if (turnstileEl) {
31
+ const sitekey = turnstileEl.getAttribute('data-sitekey') || '';
32
+ return { type: 'turnstile', sitekey };
33
+ }
34
+ return null;
35
+ });
36
+ if (!captchaInfo?.sitekey)
37
+ return null;
38
+ const token = provider === 'capsolver'
39
+ ? await solveWithCapSolver(captchaInfo.type, captchaInfo.sitekey, pageUrl, apiKey)
40
+ : await solveWith2Captcha(captchaInfo.type, captchaInfo.sitekey, pageUrl, apiKey);
41
+ // Inject the token into the page
42
+ await page.evaluate((t, type) => {
43
+ // reCAPTCHA
44
+ if (type === 'recaptcha') {
45
+ const el = document.querySelector('textarea.g-recaptcha-response');
46
+ if (el) {
47
+ el.value = t;
48
+ }
49
+ // Also trigger the callback if registered
50
+ if (window.grecaptcha?.getResponse && document.querySelector('[data-callback]')) {
51
+ const cb = document.querySelector('[data-callback]')?.getAttribute('data-callback');
52
+ if (cb && window[cb])
53
+ window[cb](t);
54
+ }
55
+ }
56
+ // hCaptcha
57
+ if (type === 'hcaptcha') {
58
+ const el = document.querySelector('textarea[name="h-captcha-response"]');
59
+ if (el) {
60
+ el.value = t;
61
+ }
62
+ }
63
+ // Turnstile
64
+ if (type === 'turnstile') {
65
+ const el = document.querySelector('[name="cf-turnstile-response"]');
66
+ if (el) {
67
+ el.value = t;
68
+ }
69
+ }
70
+ }, token, captchaInfo.type);
71
+ return { token, provider };
49
72
  }
50
73
  async function solveWith2Captcha(type, sitekey, pageUrl, apiKey) {
51
- const method = type === "hcaptcha" ? "hcaptcha" : type === "turnstile" ? "turnstile" : "userrecaptcha";
52
- const submitRes = await fetch("http://2captcha.com/in.php", {
53
- method: "POST",
54
- body: new URLSearchParams({
55
- key: apiKey,
56
- method,
57
- googlekey: sitekey,
58
- pageurl: pageUrl,
59
- json: "1"
60
- })
61
- });
62
- const submitData = await submitRes.json();
63
- if (submitData.status !== 1) throw new Error(`2captcha submit failed: ${submitData.request}`);
64
- const taskId = submitData.request;
65
- for (let i = 0; i < MAX_ATTEMPTS; i++) {
66
- await new Promise((r) => setTimeout(r, POLL_INTERVAL_MS));
67
- const pollRes = await fetch(`http://2captcha.com/res.php?key=${apiKey}&action=get&id=${taskId}&json=1`);
68
- const pollData = await pollRes.json();
69
- if (pollData.status === 1) return pollData.request;
70
- if (pollData.request !== "CAPCHA_NOT_READY") throw new Error(`2captcha error: ${pollData.request}`);
71
- }
72
- throw new Error("2captcha timed out after 2 minutes");
74
+ const method = type === 'hcaptcha' ? 'hcaptcha' : type === 'turnstile' ? 'turnstile' : 'userrecaptcha';
75
+ const submitRes = await fetch('http://2captcha.com/in.php', {
76
+ method: 'POST',
77
+ body: new URLSearchParams({
78
+ key: apiKey,
79
+ method,
80
+ googlekey: sitekey,
81
+ pageurl: pageUrl,
82
+ json: '1',
83
+ }),
84
+ });
85
+ const submitData = await submitRes.json();
86
+ if (submitData.status !== 1)
87
+ throw new Error(`2captcha submit failed: ${submitData.request}`);
88
+ const taskId = submitData.request;
89
+ // Poll for result
90
+ for (let i = 0; i < MAX_ATTEMPTS; i++) {
91
+ await new Promise(r => setTimeout(r, POLL_INTERVAL_MS));
92
+ const pollRes = await fetch(`http://2captcha.com/res.php?key=${apiKey}&action=get&id=${taskId}&json=1`);
93
+ const pollData = await pollRes.json();
94
+ if (pollData.status === 1)
95
+ return pollData.request;
96
+ if (pollData.request !== 'CAPCHA_NOT_READY')
97
+ throw new Error(`2captcha error: ${pollData.request}`);
98
+ }
99
+ throw new Error('2captcha timed out after 2 minutes');
73
100
  }
74
101
  async function solveWithCapSolver(type, sitekey, pageUrl, apiKey) {
75
- const taskType = type === "hcaptcha" ? "HCaptchaTaskProxyless" : type === "turnstile" ? "AntiTurnstileTaskProxyless" : "ReCaptchaV2TaskProxyless";
76
- const createRes = await fetch("https://api.capsolver.com/createTask", {
77
- method: "POST",
78
- headers: { "Content-Type": "application/json" },
79
- body: JSON.stringify({
80
- clientKey: apiKey,
81
- task: { type: taskType, websiteURL: pageUrl, websiteKey: sitekey }
82
- })
83
- });
84
- const createData = await createRes.json();
85
- if (createData.errorId !== 0) throw new Error(`CapSolver create failed: ${createData.errorDescription}`);
86
- const taskId = createData.taskId;
87
- for (let i = 0; i < MAX_ATTEMPTS; i++) {
88
- await new Promise((r) => setTimeout(r, POLL_INTERVAL_MS));
89
- const pollRes = await fetch("https://api.capsolver.com/getTaskResult", {
90
- method: "POST",
91
- headers: { "Content-Type": "application/json" },
92
- body: JSON.stringify({ clientKey: apiKey, taskId })
102
+ const taskType = type === 'hcaptcha' ? 'HCaptchaTaskProxyless'
103
+ : type === 'turnstile' ? 'AntiTurnstileTaskProxyless'
104
+ : 'ReCaptchaV2TaskProxyless';
105
+ const createRes = await fetch('https://api.capsolver.com/createTask', {
106
+ method: 'POST',
107
+ headers: { 'Content-Type': 'application/json' },
108
+ body: JSON.stringify({
109
+ clientKey: apiKey,
110
+ task: { type: taskType, websiteURL: pageUrl, websiteKey: sitekey },
111
+ }),
93
112
  });
94
- const pollData = await pollRes.json();
95
- if (pollData.errorId !== 0) throw new Error(`CapSolver error: ${pollData.errorDescription}`);
96
- if (pollData.status === "ready") {
97
- return pollData.solution?.gRecaptchaResponse ?? pollData.solution?.token ?? "";
113
+ const createData = await createRes.json();
114
+ if (createData.errorId !== 0)
115
+ throw new Error(`CapSolver create failed: ${createData.errorDescription}`);
116
+ const taskId = createData.taskId;
117
+ for (let i = 0; i < MAX_ATTEMPTS; i++) {
118
+ await new Promise(r => setTimeout(r, POLL_INTERVAL_MS));
119
+ const pollRes = await fetch('https://api.capsolver.com/getTaskResult', {
120
+ method: 'POST',
121
+ headers: { 'Content-Type': 'application/json' },
122
+ body: JSON.stringify({ clientKey: apiKey, taskId }),
123
+ });
124
+ const pollData = await pollRes.json();
125
+ if (pollData.errorId !== 0)
126
+ throw new Error(`CapSolver error: ${pollData.errorDescription}`);
127
+ if (pollData.status === 'ready') {
128
+ return pollData.solution?.gRecaptchaResponse ?? pollData.solution?.token ?? '';
129
+ }
98
130
  }
99
- }
100
- throw new Error("CapSolver timed out after 2 minutes");
131
+ throw new Error('CapSolver timed out after 2 minutes');
101
132
  }
102
- export {
103
- solveCaptcha
104
- };
105
- //# sourceMappingURL=captcha-solver.js.map