-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
59 lines (49 loc) · 1.62 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
import { firefox } from "playwright";
const APIKEY = process.env.APIKEY || "2captcha_api_key"; // set you 2captcha apikey
import { Solver } from "2captcha-ts";
const solver = new Solver(APIKEY);
const sleep = (ms) => new Promise((res) => setTimeout(res, ms));
;(async () => {
const browser = await firefox.launch({
headless: false,
devtools: true,
});
const context = await browser.newContext();
const page = await context.newPage();
// Open target page
await page.goto("https://www.payback.de/login");
// Waiting for the frame
await page.waitForSelector("#main-iframe");
// Getting the frame
const iframeElementHandle = await page.$("#main-iframe");
const iframe = await iframeElementHandle.contentFrame();
// Let's wait a bit
await sleep(2000);
// Grab the captcha parameters
const params = await iframe.evaluate(() => {
const sitekey = document.querySelector(".g-recaptcha").dataset.sitekey;
const pageurl = window.location.href;
return {
pageurl,
sitekey,
};
});
// Show the found captcha parameters to the console
console.log(params);
// Sending a captcha to the 2captcha service
solver
.recaptcha({
pageurl: params.pageurl,
googlekey: params.sitekey,
})
.then(async (res) => {
// We output the result of the captcha solution to the console
console.log(res);
// We apply the received token on the page
await iframe.evaluate((res) => {
document.querySelector("#g-recaptcha-response").value = res.data;
onCaptchaFinished(res.data);
}, res);
// Do whatever you want on this page
});
})();