can reset browser

This commit is contained in:
2022-10-05 10:58:24 +02:00
parent 57df041a0e
commit 38ccbad3ea
2 changed files with 35 additions and 19 deletions
+1 -1
View File
@@ -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
+17 -1
View File
@@ -51,8 +51,9 @@ async function sendRequest(fileName, callback) {
}
class GeoCaptchaSolver {
constructor(page) {
constructor(page, device) {
this.page = page;
this.device = device;
}
async solve(onResult) {
@@ -65,6 +66,7 @@ class GeoCaptchaSolver {
let captcha_container = await iframeHandler.locator(CAPTCHA_CONTAINER)
let html = await captcha_container.innerHTML()
console.log("audio_tag: " + html);
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++) {
@@ -82,6 +84,10 @@ class GeoCaptchaSolver {
}
}
)
} 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
}
}