summaryrefslogtreecommitdiff
path: root/index.js
blob: 90658f0be0a389fe8876fdc2f8c827e672cf6885 (plain)
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
const puppeteer = require('puppeteer-extra');
const StealthPlugin = require('puppeteer-extra-plugin-stealth')
puppeteer.use(StealthPlugin());
const Koa = require('koa');
const app = new Koa();

(async () => {
    const browser = await puppeteer.launch({
        headless: true,
        executablePath: '/usr/bin/chromium-browser',
        args: ['--no-sandbox', '--disable-setuid-sandbox']
    });
    app.use(async ctx => {
        if (ctx.query.url) {
            const page = await browser.newPage();
            await page.goto(ctx.query.url);
            if ((await page.content()).includes("cloudflare"))
                await page.waitForNavigation();
            ctx.body = await page.content();
            await page.close();
        }
        else {
            ctx.body = "Please specify the URL query string.";
        }
    });
    app.listen(3000);
})();