Improved puppeteer bypass, enabled for Team Skeet.

This commit is contained in:
DebaucheryLibrarian 2023-06-10 02:05:59 +02:00
parent 09a48ed064
commit 80334843c9
7 changed files with 1065 additions and 170 deletions

View File

@ -303,6 +303,7 @@ module.exports = {
enable: false,
hostnames: [ // these can run in the same browser session
'www.kink.com',
'store2.psmcdn.net', // Team Skeet API
],
},
cloudflare: {

1194
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -125,9 +125,9 @@
"postgraphile-plugin-connection-filter": "^2.2.2",
"promise-task-queue": "^1.2.0",
"prop-types": "^15.7.2",
"puppeteer": "^18.2.0",
"puppeteer-extra": "^3.3.4",
"puppeteer-extra-plugin-stealth": "^2.11.1",
"puppeteer": "^20.5.0",
"puppeteer-extra": "^3.3.6",
"puppeteer-extra-plugin-stealth": "^2.11.2",
"sharp": "^0.29.2",
"showdown": "^1.9.1",
"source-map-support": "^0.5.16",

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 446 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

View File

@ -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,