修复A2C工单蜘蛛
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
/**
|
||||
* Cloudflare / Turnstile 挑战页检测
|
||||
*
|
||||
* antiBot.cfClearanceRequired === false(A2C 业务域):仅真实 CF 中间页算 blocked,
|
||||
* 不因页面引用 turnstile.js 或缺少 cf_clearance cookie 误判。
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -17,6 +20,14 @@ function urlIndicatesCfChallenge(url) {
|
||||
|| url.includes('/cdn-cgi/challenge');
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否要求 cf_clearance 才视为过盾完成(A2C user.a2c.chat 为 false)
|
||||
* @param {object|null|undefined} antiBot
|
||||
*/
|
||||
function isCfClearanceRequired(antiBot) {
|
||||
return antiBot?.cfClearanceRequired !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {Object} CloudflareState
|
||||
* @property {boolean} blocked 是否处于 CF 挑战中
|
||||
@@ -29,9 +40,10 @@ function urlIndicatesCfChallenge(url) {
|
||||
/**
|
||||
* 检测页面是否被 Cloudflare 拦截
|
||||
* @param {import('puppeteer').Page} page
|
||||
* @param {object|null} [antiBot]
|
||||
* @returns {Promise<CloudflareState>}
|
||||
*/
|
||||
async function detectCloudflare(page) {
|
||||
async function detectCloudflare(page, antiBot = null) {
|
||||
const url = page.url();
|
||||
const title = await page.title().catch(() => '');
|
||||
|
||||
@@ -61,22 +73,28 @@ async function detectCloudflare(page) {
|
||||
|
||||
const urlChallenge = urlIndicatesCfChallenge(url);
|
||||
|
||||
const realChallenge = urlChallenge
|
||||
|| domSignals.titleHasJustAMoment
|
||||
|| domSignals.bodyHasJustAMoment
|
||||
|| domSignals.hasChallengeRunning
|
||||
|| title.includes('Just a moment');
|
||||
|
||||
const turnstileSignals = domSignals.hasTurnstileInput || domSignals.hasTurnstileWidget;
|
||||
|
||||
let challengeType = null;
|
||||
if (domSignals.hasTurnstileInput || domSignals.hasTurnstileWidget || url.includes('__cf_chl')) {
|
||||
if (turnstileSignals || url.includes('__cf_chl')) {
|
||||
challengeType = 'turnstile';
|
||||
} else if (urlChallenge || domSignals.titleHasJustAMoment || domSignals.bodyHasJustAMoment) {
|
||||
} else if (realChallenge) {
|
||||
challengeType = 'js_challenge';
|
||||
}
|
||||
|
||||
const blocked = !hasCfClearance && (
|
||||
urlChallenge
|
||||
|| domSignals.titleHasJustAMoment
|
||||
|| domSignals.bodyHasJustAMoment
|
||||
|| domSignals.hasTurnstileInput
|
||||
|| domSignals.hasTurnstileWidget
|
||||
|| domSignals.hasChallengeRunning
|
||||
|| title.includes('Just a moment')
|
||||
);
|
||||
const requireClearance = isCfClearanceRequired(antiBot);
|
||||
let blocked;
|
||||
if (requireClearance) {
|
||||
blocked = !hasCfClearance && (realChallenge || turnstileSignals);
|
||||
} else {
|
||||
blocked = realChallenge;
|
||||
}
|
||||
|
||||
return {
|
||||
blocked,
|
||||
@@ -110,4 +128,5 @@ module.exports = {
|
||||
detectCloudflare,
|
||||
isTurnstileSolved,
|
||||
urlIndicatesCfChallenge,
|
||||
isCfClearanceRequired,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user