can reset browser
This commit is contained in:
@@ -331,7 +331,7 @@ class CommandorPage {
|
||||
if (audioBtn) {
|
||||
log("audioBtn found")
|
||||
audioBtn.click()
|
||||
let captchaSolver = new GeoCaptchaSolver(this.page)
|
||||
let captchaSolver = new GeoCaptchaSolver(this.page, this.device)
|
||||
await captchaSolver.solve((isSuccessful) => {
|
||||
if (!isSuccessful) {
|
||||
this.isTerminated = true
|
||||
|
||||
@@ -51,10 +51,11 @@ async function sendRequest(fileName, callback) {
|
||||
}
|
||||
|
||||
class GeoCaptchaSolver {
|
||||
constructor(page) {
|
||||
constructor(page, device) {
|
||||
this.page = page;
|
||||
this.device = device;
|
||||
}
|
||||
|
||||
|
||||
async solve(onResult) {
|
||||
console.log("solve() called.")
|
||||
console.log("play audio")
|
||||
@@ -65,23 +66,28 @@ class GeoCaptchaSolver {
|
||||
let captcha_container = await iframeHandler.locator(CAPTCHA_CONTAINER)
|
||||
let html = await captcha_container.innerHTML()
|
||||
console.log("audio_tag: " + html);
|
||||
// find wav from html
|
||||
await this.findTextFromWavFile(html, async (number_list) => {
|
||||
for (let i = 1; i <= number_list.length; i++) {
|
||||
let selector = "#captcha__audio > div.audio-captcha-input-container > input:nth-child(" + i + ")"
|
||||
// console.log("selector is " + selector)
|
||||
await iframeHandler.locator(selector).focus()
|
||||
await iframeHandler.locator(selector).fill("" + number_list[i - 1])
|
||||
// fieldInputs[i].value = number_list[i];
|
||||
await delay(2000 + getRandomWaitTime());
|
||||
if (!html.includes("You have been blocked")) {
|
||||
// find wav from html
|
||||
await this.findTextFromWavFile(html, async (number_list) => {
|
||||
for (let i = 1; i <= number_list.length; i++) {
|
||||
let selector = "#captcha__audio > div.audio-captcha-input-container > input:nth-child(" + i + ")"
|
||||
// console.log("selector is " + selector)
|
||||
await iframeHandler.locator(selector).focus()
|
||||
await iframeHandler.locator(selector).fill("" + number_list[i - 1])
|
||||
// fieldInputs[i].value = number_list[i];
|
||||
await delay(2000 + getRandomWaitTime());
|
||||
}
|
||||
if (number_list.isEmpty()) {
|
||||
onResult(false)
|
||||
} else {
|
||||
onResult(true)
|
||||
}
|
||||
}
|
||||
if (number_list.isEmpty()) {
|
||||
onResult(false)
|
||||
} else {
|
||||
onResult(true)
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
} else {
|
||||
await this.resetBrowser()
|
||||
onResult(false)
|
||||
}
|
||||
}
|
||||
|
||||
async findTextFromWavFile(html, callback) {
|
||||
@@ -104,6 +110,16 @@ class GeoCaptchaSolver {
|
||||
}
|
||||
}
|
||||
|
||||
async resetBrowser() {
|
||||
console.log("will reset browser")
|
||||
await this.device.shell("pm clear com.android.chrome")
|
||||
await delay(1000)
|
||||
await this.device.shell("am set-debug-app --persistent com.android.chrome")
|
||||
await delay(1000)
|
||||
await this.device.shell("pm am start -n com.android.chrome/com.google.android.apps.chrome.Main")
|
||||
await delay(1000)
|
||||
this.isTerminated = true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user