add support for LinkValidator

This commit is contained in:
2022-12-09 09:59:11 +01:00
parent 82b297fdd3
commit 7fea859e29
3 changed files with 60 additions and 37 deletions
+40 -34
View File
@@ -30,6 +30,7 @@ REGEX_RDV_URL = "https:\/\/rendezvousparis\.hermes\.com\/client\/register\/[A-Z0
const PLAY_AUDIO_BTN_ID = ".audio-captcha-play-button"
const homedir = require('os').homedir();
const CAPTCHA_CONTAINER = "#captcha-container";
function delay(delayInMs) {
return new Promise(resolve => {
setTimeout(() => {
@@ -62,44 +63,49 @@ class LinkValidator {
// Connect to the device.
log("loadPage() called for url " + this.urlToValidate);
// await this.device.shell('am force-stop com.android.chrome');
const context = await this.device.launchBrowser();
// await context.clearCookies()
// Use BrowserContext as usual.
this.page = await context.newPage();
this.page.on("load", (loadedPage) => {
this.onPageLoad(loadedPage)
})
this.page.on("response", (response) => {
this.onResponse(response)
})
try {
await this.page.goto(this.urlToValidate, {timeout: 90 * 1000});
const context = await this.device.launchBrowser();
// await context.clearCookies()
// Use BrowserContext as usual.
this.page = await context.newPage();
this.page.on("load", (loadedPage) => {
this.onPageLoad(loadedPage)
})
this.page.on("response", (response) => {
this.onResponse(response)
})
try {
await this.page.goto(this.urlToValidate, {timeout: 90 * 1000});
} catch (e) {
log(e)
this.isTerminated = true
}
let cancel
const intervalTask = setInterval(() => {
if (this.isTerminated) {
log("request terminated, will close device")
context.close()
// this.page.close()
this.device.close()
clearInterval(intervalTask)
cancel()
return context
}
}, 10 * 1000)//interval of 10 seconds
await new Promise(function (fulfill, reject) {
cancel = function () {
fulfill(Promise.resolve())
}
setTimeout(fulfill, TIME_OUT, 5)
}).then(log)
} catch (e) {
log(e)
this.isTerminated = true
console.log(e)
}
let cancel
const intervalTask = setInterval(() => {
if (this.isTerminated) {
log("request terminated, will close device")
context.close()
// this.page.close()
this.device.close()
clearInterval(intervalTask)
cancel()
return context
}
}, 10 * 1000)//interval of 10 seconds
await new Promise(function (fulfill, reject) {
cancel = function () {
fulfill(Promise.resolve())
}
setTimeout(fulfill, TIME_OUT, 5)
}).then(log)
}
async onPageLoad(currentPage) {