add timeout for pages()
This commit is contained in:
@@ -32,6 +32,8 @@ const MESSAGE_URL_VALIDATION_FR = "Nous avons envoyé un lien par e-mail."
|
|||||||
const MESSAGE_URL_VALIDATION_EN = "Please click on the link we sent by email"
|
const MESSAGE_URL_VALIDATION_EN = "Please click on the link we sent by email"
|
||||||
const REGEX_RDV_URL = "https:\/\/rendezvousparis\.hermes\.com\/client\/register\/[A-Z0-9]+"
|
const REGEX_RDV_URL = "https:\/\/rendezvousparis\.hermes\.com\/client\/register\/[A-Z0-9]+"
|
||||||
const DEFAULT_STORE = 'faubourg';
|
const DEFAULT_STORE = 'faubourg';
|
||||||
|
const timeout = (prom, time) =>
|
||||||
|
Promise.race([prom, new Promise((_r, rej) => setTimeout(rej, time))]);
|
||||||
|
|
||||||
function delay(delayInMs) {
|
function delay(delayInMs) {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
@@ -178,8 +180,9 @@ class CommandorPage {
|
|||||||
if (this.isTerminated) {
|
if (this.isTerminated) {
|
||||||
log(this.device.model() + ":request terminated, send cancel()");
|
log(this.device.model() + ":request terminated, send cancel()");
|
||||||
try {
|
try {
|
||||||
if (this.page !== undefined)
|
if (this.page !== undefined) {
|
||||||
await this.page.close()
|
await this.page.close()
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e)
|
console.log(e)
|
||||||
}
|
}
|
||||||
@@ -786,7 +789,6 @@ class CommandorPage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async checkResultWithOcr() {
|
async checkResultWithOcr() {
|
||||||
logWithDevice("checkResultWithOcr() called.", this.device)
|
logWithDevice("checkResultWithOcr() called.", this.device)
|
||||||
if (this.device.model() === "M2006C3LG")
|
if (this.device.model() === "M2006C3LG")
|
||||||
@@ -806,7 +808,9 @@ class CommandorPage {
|
|||||||
await this.slidingCaptcha(async (isSuccessful) => {
|
await this.slidingCaptcha(async (isSuccessful) => {
|
||||||
logWithDevice("SLIDING_CAPTCHA result is " + isSuccessful, this.device)
|
logWithDevice("SLIDING_CAPTCHA result is " + isSuccessful, this.device)
|
||||||
if (isSuccessful) {
|
if (isSuccessful) {
|
||||||
|
await delay(5 * 1000)
|
||||||
checkResult = await this.ocrChecker.get_result();
|
checkResult = await this.ocrChecker.get_result();
|
||||||
|
console.log(checkResult);
|
||||||
} else {
|
} else {
|
||||||
checkResult = OCRResult.TERMINAED
|
checkResult = OCRResult.TERMINAED
|
||||||
this.isTerminated = true
|
this.isTerminated = true
|
||||||
@@ -836,41 +840,61 @@ class CommandorPage {
|
|||||||
browserWSEndpoint: "ws://127.0.0.1:" + this.port + "/devtools/browser",
|
browserWSEndpoint: "ws://127.0.0.1:" + this.port + "/devtools/browser",
|
||||||
headless: false, defaultViewport: null
|
headless: false, defaultViewport: null
|
||||||
})
|
})
|
||||||
logWithDevice("get pages", this.device)
|
|
||||||
let pages = await this.browser.pages();
|
|
||||||
try {
|
try {
|
||||||
for (const currentPage of pages) {
|
logWithDevice("get pages", this.device)
|
||||||
|
// let pages = await this.browser.pages();
|
||||||
|
let pages = await timeout(this.browser.pages(), 5 * 1000);
|
||||||
|
pages.forEach((currentPage) => {
|
||||||
if (currentPage.url() === RDV_URL) {
|
if (currentPage.url() === RDV_URL) {
|
||||||
logWithDevice("get content", this.device)
|
this.page = currentPage;
|
||||||
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 {
|
} else {
|
||||||
try {
|
try {
|
||||||
await currentPage.close()
|
currentPage.close()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e)
|
console.log(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
} catch (e) {
|
logWithDevice("this.page.bringToFront();", this.device)
|
||||||
this.isTerminated = true;
|
|
||||||
console.log(e)
|
await this.page.bringToFront();
|
||||||
}
|
await this.fillFields(this.page)
|
||||||
logWithDevice("this.page.bringToFront();", this.device)
|
await delay(2 * 1000);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
|
await this.resetBrowser()
|
||||||
|
// this.isTerminated = true;
|
||||||
|
}
|
||||||
|
// try {
|
||||||
|
// for (const currentPage of pages) {
|
||||||
|
// if (currentPage.url() === RDV_URL) {
|
||||||
|
// 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 {
|
||||||
|
// await currentPage.close()
|
||||||
|
// } catch (e) {
|
||||||
|
// console.log(e)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// } catch (e) {
|
||||||
|
// this.isTerminated = true;
|
||||||
|
// console.log(e)
|
||||||
|
// }
|
||||||
|
|
||||||
await this.page.bringToFront();
|
|
||||||
await this.fillFields(this.page)
|
|
||||||
await delay(2 * 1000);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e)
|
console.log(e)
|
||||||
this.isTerminated = true
|
this.isTerminated = true
|
||||||
@@ -879,27 +903,7 @@ class CommandorPage {
|
|||||||
logWithDevice("this.browser.isConnected() is " + this.browser.isConnected(), this.device)
|
logWithDevice("this.browser.isConnected() is " + this.browser.isConnected(), this.device)
|
||||||
try {
|
try {
|
||||||
if (this.browser.isConnected()) {
|
if (this.browser.isConnected()) {
|
||||||
// logWithDevice("get pages", this.device)
|
|
||||||
// let pages = await this.browser.pages();
|
|
||||||
logWithDevice("will use old page", this.device)
|
logWithDevice("will use old page", this.device)
|
||||||
// try {
|
|
||||||
// pages.forEach((currentPage) => {
|
|
||||||
// if (currentPage.url() === RDV_URL) {
|
|
||||||
// this.page = currentPage;
|
|
||||||
// } else {
|
|
||||||
// // try {
|
|
||||||
// // if (!currentPage.isClosed()) {
|
|
||||||
// // currentPage.close()
|
|
||||||
// // }
|
|
||||||
// // } catch (e) {
|
|
||||||
// // console.log(e)
|
|
||||||
// // }
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
// } catch (e) {
|
|
||||||
// this.isTerminated = true
|
|
||||||
// console.log(e)
|
|
||||||
// }
|
|
||||||
logWithDevice("this.page.bringToFront();", this.device)
|
logWithDevice("this.page.bringToFront();", this.device)
|
||||||
await this.page.bringToFront();
|
await this.page.bringToFront();
|
||||||
// this.page = pages;
|
// this.page = pages;
|
||||||
|
|||||||
@@ -194,6 +194,7 @@ class OCRChecker {
|
|||||||
async take_screen_shot() {
|
async take_screen_shot() {
|
||||||
let name = this.get_file_name()
|
let name = this.get_file_name()
|
||||||
console.log("will take screenshot for " + this.device.model() + ":" + this.device.serial())
|
console.log("will take screenshot for " + this.device.model() + ":" + this.device.serial())
|
||||||
|
console.log("name is " + name)
|
||||||
let stdout1 = await exec("adb -s " + this.device.serial() + " exec-out screencap -p > " + name)
|
let stdout1 = await exec("adb -s " + this.device.serial() + " exec-out screencap -p > " + name)
|
||||||
await delay(5000);
|
await delay(5000);
|
||||||
console.log(`stdout: ${stdout1}`);
|
console.log(`stdout: ${stdout1}`);
|
||||||
|
|||||||
@@ -34,17 +34,18 @@ class SlidingCaptchaSolver {
|
|||||||
let stdout1 = await exec("adb -s " + device.serial() + " exec-out screencap -p > " + name)
|
let stdout1 = await exec("adb -s " + device.serial() + " exec-out screencap -p > " + name)
|
||||||
// await delay(5000);
|
// await delay(5000);
|
||||||
console.log(`stdout: ${stdout1}`);
|
console.log(`stdout: ${stdout1}`);
|
||||||
await delay(1000);
|
await delay(5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async sliding_captcha(device, onResult) {
|
async sliding_captcha(device, onResult) {
|
||||||
// take screenshot
|
// take screenshot
|
||||||
console.log("take screenshot")
|
console.log("sliding_captcha.take screenshot")
|
||||||
let blockedFileName = uuidv4();
|
let blockedFileName = uuidv4();
|
||||||
let blockedImageFileName = "blocked_" + blockedFileName + ".png"
|
let blockedImageFileName = "blocked_" + blockedFileName + ".png"
|
||||||
await this.take_screen_shot(blockedImageFileName, device)
|
await this.take_screen_shot(blockedImageFileName, device)
|
||||||
//get resolution of screen
|
//get resolution of screen
|
||||||
|
console.log("sliding_captcha.sendRequest:" + blockedImageFileName)
|
||||||
await this.sendRequest(blockedImageFileName, async (detectedPositionList) => {
|
await this.sendRequest(blockedImageFileName, async (detectedPositionList) => {
|
||||||
console.log("detectedPosition: " + device.model() + ":" + detectedPositionList);
|
console.log("detectedPosition: " + device.model() + ":" + detectedPositionList);
|
||||||
if (detectedPositionList.length >= 2) {
|
if (detectedPositionList.length >= 2) {
|
||||||
@@ -81,6 +82,7 @@ class SlidingCaptchaSolver {
|
|||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteFile(filename) {
|
async deleteFile(filename) {
|
||||||
try {
|
try {
|
||||||
fs.unlinkSync(filename)
|
fs.unlinkSync(filename)
|
||||||
@@ -89,6 +91,7 @@ class SlidingCaptchaSolver {
|
|||||||
return OCRResult.TERMINAED
|
return OCRResult.TERMINAED
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendRequest(fileName, callback) {
|
async sendRequest(fileName, callback) {
|
||||||
const fileStream = fs.createReadStream(fileName);
|
const fileStream = fs.createReadStream(fileName);
|
||||||
let response = await axios.post(DEEPLEARNING_CAPTCHA_HOST, fileStream, {
|
let response = await axios.post(DEEPLEARNING_CAPTCHA_HOST, fileStream, {
|
||||||
|
|||||||
Reference in New Issue
Block a user