From 939b98e3a3b3533d3141de7318584ca949c64ab8 Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Wed, 29 Nov 2023 17:14:59 +0100 Subject: [PATCH] handle ssl error --- package.json | 2 +- src/models/OCRResult.js | 2 ++ src/workers/CommandorPage.js | 39 ++++++++++++++++++++++-------------- src/workers/OCRChecker.js | 14 +++++++++++-- 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index dfdd90a..0efab76 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "node-wget": "^0.4.3", "node-xlsx": "^0.21.0", "playwright": "^1.39.0", - "puppeteer": "^15.5.0", + "puppeteer": "^15.2.0", "read-ini-file": "^3.0.1", "uuid": "^9.0.0", "winston": "^3.8.2", diff --git a/src/models/OCRResult.js b/src/models/OCRResult.js index b2180e2..6586681 100644 --- a/src/models/OCRResult.js +++ b/src/models/OCRResult.js @@ -3,6 +3,8 @@ const OCRResult = { TO_REFRESH: Symbol("TO_REFRESH"), BLOCKED: Symbol("BLOCKED"), SLIDING_CAPTCHA: Symbol("SLIDING_CAPTCHA"), + SSL_CERT_ERROR: Symbol("SSL_CERT_ERROR"), + SLIDING_CAPTCHA_LOADING: Symbol("SLIDING_CAPTCHA_LOADING"), SLIDING_CAPTCHA_REFRESH: Symbol("SLIDING_CAPTCHA_REFRESH"), FILL_FIELD: Symbol("FILL_FIELD"), NEED_TO_CLICK_LATE_BTN: Symbol("NEED_TO_CLICK_LATE_BTN"), diff --git a/src/workers/CommandorPage.js b/src/workers/CommandorPage.js index 782b090..3966fa6 100644 --- a/src/workers/CommandorPage.js +++ b/src/workers/CommandorPage.js @@ -178,7 +178,8 @@ class CommandorPage { if (this.isTerminated) { log(this.device.model() + ":request terminated, send cancel()"); try { - await this.page.close() + if (this.page !== undefined) + await this.page.close() } catch (e) { console.log(e) } @@ -726,16 +727,6 @@ class CommandorPage { await this.checkResultWithOcr(); if (this.page.url() === BLANK_URL) { this.isTerminated = true; - } else { - try { - // let errorItem = this.page.locator("div.alert"); - // if (errorItem) { - // let errorContent = await errorItem.innerHTML(); - // await this.handleError(errorContent); - // } - } catch (e) { - log(e); - } } } @@ -824,6 +815,12 @@ class CommandorPage { await delay(10 * 1000) } switch (checkResult) { + case OCRResult.SLIDING_CAPTCHA_LOADING: + this.isTerminated = true; + break; + case OCRResult.SSL_CERT_ERROR: + await this.resetBrowser() + break; case OCRResult.TERMINAED: this.isTerminated = true; break; @@ -842,17 +839,29 @@ class CommandorPage { logWithDevice("get pages", this.device) let pages = await this.browser.pages(); try { - pages.forEach((currentPage) => { + for (const currentPage of pages) { if (currentPage.url() === RDV_URL) { - this.page = currentPage; + logWithDevice("get content", this.device) + let pageContent = await currentPage.content() + logWithDevice("content:" + pageContent, this.device) + if (!pageContent.includes("geo.captcha-delivery.com")) { + this.page = currentPage; + break + } else { + try { + await currentPage.close() + } catch (e) { + console.log(e) + } + } } else { try { - currentPage.close() + await currentPage.close() } catch (e) { console.log(e) } } - }) + } } catch (e) { this.isTerminated = true; console.log(e) diff --git a/src/workers/OCRChecker.js b/src/workers/OCRChecker.js index aaa9374..12019e0 100644 --- a/src/workers/OCRChecker.js +++ b/src/workers/OCRChecker.js @@ -17,6 +17,7 @@ const NO_INTERNET_FR_2 = "Aucun accès à Internet" const BRAVE_VPN_SKIP = "Pare-feu + VPN Brave" const MESSAGE_URL_VALIDATION_FR = "envoyé un lien par e-mail." const MESSAGE_URL_VALIDATION_FR_2 = "un lien par e-mail" +const SSL_CERT_ERROR = " Votre connexion n'est pas privée" const MESSAGE_URL_VALIDATION_EN = "Please click on the link we sent by email" const CHOOSE_POSITION_GOOGLE_FR = " Choisir la position pour les résultats de recherche" const CAPTCHA_ERROR_MESSAGE = "Error verifying captcha, please try again" @@ -31,11 +32,14 @@ const ERR_CACHE_MISS = "ERR_CACHE_MISS" const ERR_CACHE_MISS_2 = "ERR_CACHE-MISS" const ERR_CACHE_MISS_3 = "appuyer sur le bouton d'actualisation" const ERR_CACHE_MISS_4 = "renvoyer les données" +const ERR_EMPTY_RESPONSE = "ERR_EMPTY_RESPONSE" const SLIDING_CAPTCHA_FR = "Pourquoi cette vérification" +const SLIDING_CAPTCHA_LOADING_FR = "Chargement." const SLIDING_CAPTCHA_FR_2 = "Glissez vers la droite pour" const SLIDING_CAPTCHA_FR_3 = "la droite pour completer le puzzle" const SLIDING_CAPTCHA_FR_4 = " s'assure qu'on s'adresse bien" const SLIDING_CAPTCHA_FR_5 = "On s'assure que c'est" +const SLIDING_CAPTCHA_FR_6 = "s'assure que cest bien vous" const MESSAGE_FILL_FIELD_FR = "Demande de rendez-vous pour" const MESSAGE_FILL_FIELD_FR_2 = "des champs de données doivent étre complétés" const MESSAGE_FILL_FIELD_FR_3 = "Sans préféré" @@ -100,6 +104,9 @@ class OCRChecker { } else if (result.includes(BRAVE_VPN_SKIP)) { await this.deleteFile(fileName) return OCRResult.BRAVE_VPN_SKIP + } else if (result.includes(SSL_CERT_ERROR)) { + await this.deleteFile(fileName) + return OCRResult.SSL_CERT_ERROR } else if (result.includes(MESSAGE_FILL_FIELD_FR) || result.includes(MESSAGE_FILL_FIELD_FR_2) || result.includes(MESSAGE_FILL_FIELD_FR_3) || result.includes(MESSAGE_FILL_FIELD_FR_4) || result.includes(MESSAGE_FILL_FIELD_FR_5)) { await this.deleteFile(fileName) return OCRResult.FILL_FIELD @@ -108,7 +115,7 @@ class OCRChecker { } else if (result.includes(BLOCKED_MSG_EN) || result.includes(BLOCKED_MSG_FR) || result.includes(BLOCKED_MSG_FR_2) || result.includes(BLOCKED_MSG_FR_3)) { await this.deleteFile(fileName) return OCRResult.BLOCKED - } else if (result.includes(ERR_CACHE_MISS) || result.includes(ERR_CACHE_MISS_2) || result.includes(ERR_CACHE_MISS_3) || result.includes(ERR_CACHE_MISS_4)) { + } else if (result.includes(ERR_CACHE_MISS) || result.includes(ERR_CACHE_MISS_2) || result.includes(ERR_CACHE_MISS_3) || result.includes(ERR_CACHE_MISS_4) || result.includes("ERR_EMPTY_RESPONSE")) { return OCRResult.TO_REFRESH } else if (result.includes(CHECKING_MSG_FR) || result.includes(CHECKING_MSG_FR_2)) { await this.deleteFile(fileName) @@ -119,8 +126,11 @@ class OCRChecker { } else if (result.includes(BRAVE_SKIP_PUB) || result.includes(BRAVE_SKIP_PUB_2) || result.includes(BRAVE_SKIP_PUB_3) || result.includes(BRAVE_SKIP_PUB_4) || result.includes(BRAVE_SKIP_PUB_5)) { await this.deleteFile(fileName) return OCRResult.BRAVE_PRIVACY_PUB - } else if (result.includes(SLIDING_CAPTCHA_FR) || result.includes(SLIDING_CAPTCHA_FR_2) || result.includes(SLIDING_CAPTCHA_FR_3) || result.includes(SLIDING_CAPTCHA_FR_4) || result.includes(SLIDING_CAPTCHA_FR_5)) { + } else if (result.includes(SLIDING_CAPTCHA_FR) || result.includes(SLIDING_CAPTCHA_FR_2) || result.includes(SLIDING_CAPTCHA_FR_3) || result.includes(SLIDING_CAPTCHA_FR_4) || result.includes(SLIDING_CAPTCHA_FR_5) || result.includes(SLIDING_CAPTCHA_FR_6)) { await this.deleteFile(fileName) + if (result.includes(SLIDING_CAPTCHA_LOADING_FR)) { + return OCRResult.SLIDING_CAPTCHA_LOADING + } // await this.deleteFile(screenShot) // if (result.includes("rac")) // return OCRResult.SLIDING_CAPTCHA_REFRESH