Untitled

mail@pastecode.io avatar
unknown
javascript
3 years ago
2.1 kB
4
Indexable
Never
const playwright = require('playwright');
const { addExtra } = require('playwright-extra');
const HumanizePlugin = require('@extra/humanize');
const express = require('express');


//Some basic resources required by the runtime.

const app = express();

const browserContext = addExtra(playwright.firefox);
browserContext.use(
    HumanizePlugin({
        mouse: {
            showCursor: true
        }
    })
);


//Functions:
async function reloadPage(page, sitekey) {
    await page.reload();
    try {
        await page.setContent(`
        <html>
            <head>
                <script src="https://hcaptcha.com/1/api.js" async defer></script>
            </head>
            <body>
                <h1 class="shit">CaptchaAssassin</h1>
                <div class="h-captcha" data-sitekey="` + sitekey + `"></div>
            </body>
        </html>
        `, {
        waitUntil : 'load',
        timeout: 50
        });
    }
    catch (err) {

    }
}



browserContext.launch({ headless: false}).then(async browser => {
    const page = await browser.newPage();
    await page.goto("https://blank.org");

    
    let reqQueue = [];
    await page.route('**/getcaptcha', route => {
        route.abort();
        let obj = {
            url: route.request().url(),
            method: route.request().method(),
            headers: route.request().headers(),
            data: route.request().postData()
        };
        let resolver = reqQueue.shift();
        resolver(obj);
    }); 
    
    app.get('/', async (req, res) => {
        await reloadPage(page, "f5561ba9-8f1e-40ca-9b5b-a0b3f719ef34");
        await page.waitForSelector("iframe");

        const frame = await (await page.$("iframe")).contentFrame();
        await frame.click(".checkbox");

        let data = new Promise((resolve) => { reqQueue.push(resolve); })
        console.log(await data);
    });

    app.listen(5000, () => {
        console.log("CaptchaAssassin listening...")
    });

})