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 REGEX_RDV_URL = "https:\/\/rendezvousparis\.hermes\.com\/client\/register\/[A-Z0-9]+"
|
||||
const DEFAULT_STORE = 'faubourg';
|
||||
const timeout = (prom, time) =>
|
||||
Promise.race([prom, new Promise((_r, rej) => setTimeout(rej, time))]);
|
||||
|
||||
function delay(delayInMs) {
|
||||
return new Promise(resolve => {
|
||||
@@ -178,8 +180,9 @@ class CommandorPage {
|
||||
if (this.isTerminated) {
|
||||
log(this.device.model() + ":request terminated, send cancel()");
|
||||
try {
|
||||
if (this.page !== undefined)
|
||||
if (this.page !== undefined) {
|
||||
await this.page.close()
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
@@ -786,7 +789,6 @@ class CommandorPage {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async checkResultWithOcr() {
|
||||
logWithDevice("checkResultWithOcr() called.", this.device)
|
||||
if (this.device.model() === "M2006C3LG")
|
||||
@@ -806,7 +808,9 @@ class CommandorPage {
|
||||
await this.slidingCaptcha(async (isSuccessful) => {
|
||||
logWithDevice("SLIDING_CAPTCHA result is " + isSuccessful, this.device)
|
||||
if (isSuccessful) {
|
||||
await delay(5 * 1000)
|
||||
checkResult = await this.ocrChecker.get_result();
|
||||
console.log(checkResult);
|
||||
} else {
|
||||
checkResult = OCRResult.TERMINAED
|
||||
this.isTerminated = true
|
||||
@@ -836,41 +840,61 @@ class CommandorPage {
|
||||
browserWSEndpoint: "ws://127.0.0.1:" + this.port + "/devtools/browser",
|
||||
headless: false, defaultViewport: null
|
||||
})
|
||||
logWithDevice("get pages", this.device)
|
||||
let pages = await this.browser.pages();
|
||||
|
||||
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) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
this.page = currentPage;
|
||||
} else {
|
||||
try {
|
||||
await currentPage.close()
|
||||
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.fillFields(this.page)
|
||||
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) {
|
||||
console.log(e)
|
||||
this.isTerminated = true
|
||||
@@ -879,27 +903,7 @@ class CommandorPage {
|
||||
logWithDevice("this.browser.isConnected() is " + this.browser.isConnected(), this.device)
|
||||
try {
|
||||
if (this.browser.isConnected()) {
|
||||
// logWithDevice("get pages", this.device)
|
||||
// let pages = await this.browser.pages();
|
||||
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)
|
||||
await this.page.bringToFront();
|
||||
// this.page = pages;
|
||||
|
||||
Reference in New Issue
Block a user