-
Notifications
You must be signed in to change notification settings - Fork 113
/
index.js
117 lines (95 loc) · 3.76 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
const undici = require('undici')
function rdn(min, max) {
min = Math.ceil(min)
max = Math.floor(max)
return Math.floor(Math.random() * (max - min)) + min
}
async function solve(page) {
try {
await page.waitForFunction(() => {
const iframe = document.querySelector('iframe[src*="api2/anchor"]')
if (!iframe) return false
return !!iframe.contentWindow.document.querySelector('#recaptcha-anchor')
})
let frames = await page.frames()
const recaptchaFrame = frames.find(frame => frame.url().includes('api2/anchor'))
const checkbox = await recaptchaFrame.$('#recaptcha-anchor')
await checkbox.click({ delay: rdn(30, 150) })
const challenge = await page.waitForFunction(() => {
let iframe = document.querySelector('iframe[src*="api2/anchor"]')
if(iframe == null || !!iframe.contentWindow.document.querySelector('#recaptcha-anchor[aria-checked="true"]')){
return false
}
iframe = document.querySelector('iframe[src*="api2/bframe"]')
const img = iframe.contentWindow.document.querySelector('.rc-image-tile-wrapper img')
if (img && img.complete) {
return true
}
return false
}, { timeout: 5000 })
if (!challenge) return
frames = await page.frames()
const imageFrame = frames.find(frame => frame.url().includes('api2/bframe'))
const audioButton = await imageFrame.$('#recaptcha-audio-button')
await audioButton.click({ delay: rdn(30, 150) })
while (true) {
try {
await page.waitForFunction(() => {
const iframe = document.querySelector('iframe[src*="api2/bframe"]')
if (!iframe) return false
return !!iframe.contentWindow.document.querySelector('.rc-audiochallenge-tdownload-link')
}, { timeout: 5000 })
} catch (e) {
console.error(e)
continue
}
const audioLink = await page.evaluate(() => {
const iframe = document.querySelector('iframe[src*="api2/bframe"]')
return iframe.contentWindow.document.querySelector('#audio-source').src
})
const audioBytes = await page.evaluate(audioLink => {
return (async () => {
const response = await window.fetch(audioLink)
const buffer = await response.arrayBuffer()
return Array.from(new Uint8Array(buffer))
})()
}, audioLink)
const response = await undici.fetch('https://api.wit.ai/speech?v=20220622', {
method: 'POST',
body: new Uint8Array(audioBytes),
headers: {
Authorization: 'Bearer JVHWCNWJLWLGN6MFALYLHAPKUFHMNTAC',
'Content-Type': 'audio/mpeg3'
}
}).then((res) => res.text())
let audioTranscript = null
try {
audioTranscript = response.match('"text": "(.*)",')[1].trim()
} catch (e) {
const reloadButton = await imageFrame.$('#recaptcha-reload-button')
await reloadButton.click({ delay: rdn(30, 150) })
continue
}
const input = await imageFrame.$('#audio-response')
await input.click({ delay: rdn(30, 150) })
await input.type(audioTranscript, { delay: rdn(30, 75) })
const verifyButton = await imageFrame.$('#recaptcha-verify-button')
await verifyButton.click({ delay: rdn(30, 150) })
try {
await page.waitForFunction(() => {
const iframe = document.querySelector('iframe[src*="api2/anchor"]')
if(iframe == null || !!iframe.contentWindow.document.querySelector('#recaptcha-anchor[aria-checked="true"]')){
return true
}
}, { timeout: 5000 })
return page.evaluate(() => document.getElementById('g-recaptcha-response').value)
} catch (e) {
console.error(e)
continue
}
}
} catch (e) {
console.error(e)
}
}
module.exports = solve