Improved puppeteer bypass, enabled for Team Skeet.
This commit is contained in:
@@ -143,9 +143,9 @@ function getLimiter(options = {}, url) {
|
||||
return limiters[interval][concurrency];
|
||||
}
|
||||
|
||||
function extractJson(solution) {
|
||||
if (solution.headers['content-type'].includes('application/json')) {
|
||||
const { document } = new JSDOM(solution.response, { virtualConsole }).window;
|
||||
function extractJson(body, headers) {
|
||||
if (headers['content-type'].includes('application/json')) {
|
||||
const { document } = new JSDOM(body, { virtualConsole }).window;
|
||||
const dataString = document.querySelector('body > pre')?.textContent;
|
||||
|
||||
if (dataString) {
|
||||
@@ -155,14 +155,14 @@ function extractJson(solution) {
|
||||
}
|
||||
}
|
||||
|
||||
return solution.response;
|
||||
return body;
|
||||
}
|
||||
|
||||
async function getBrowserSession(identifier, options = {}) {
|
||||
return limiters.bypass.schedule(async () => {
|
||||
if (!browser) {
|
||||
browser = await puppeteer.launch({
|
||||
headless: typeof options.headless === 'undefined' ? true : options.headless,
|
||||
headless: typeof options.headless === 'undefined' ? 'new' : options.headless,
|
||||
// headless: false,
|
||||
});
|
||||
|
||||
@@ -178,20 +178,24 @@ async function getBrowserSession(identifier, options = {}) {
|
||||
}
|
||||
|
||||
async function bypassBrowserRequest(url, _options) {
|
||||
const page = await getBrowserSession(new URL(url).hostname);
|
||||
const { tab } = await getBrowserSession(new URL(url).hostname);
|
||||
|
||||
const res = await page.goto(url);
|
||||
const body = await page.content();
|
||||
const res = await tab.goto(url);
|
||||
const rawBody = await tab.content();
|
||||
|
||||
console.log(res);
|
||||
console.log(res.status());
|
||||
const headers = res.headers();
|
||||
const body = extractJson(rawBody, headers);
|
||||
|
||||
const statusCode = res.status();
|
||||
|
||||
if (!statusCode === 200) {
|
||||
throw new Error(`Puppeteer bypass failed for ${url} (${statusCode}): ${body?.message}`);
|
||||
}
|
||||
|
||||
return {
|
||||
body,
|
||||
/*
|
||||
statusCode: res.body.solution.status,
|
||||
headers: res.body.solution.headers,
|
||||
*/
|
||||
statusCode,
|
||||
headers,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -287,7 +291,7 @@ async function bypassCloudflareRequest(url, method, body, cloudflareBypass, opti
|
||||
throw new Error(`CloudFlare bypass failed for ${url} (${res.statusCode}): ${res.body?.message}`);
|
||||
}
|
||||
|
||||
const resBody = extractJson(res.body.solution);
|
||||
const resBody = extractJson(res.body.solution.response, res.body.solution.headers);
|
||||
|
||||
return {
|
||||
body: resBody,
|
||||
|
||||
Reference in New Issue
Block a user