works with disconnect

This commit is contained in:
2023-05-20 10:59:43 +02:00
parent 615431e548
commit 0c99c6b36f
3 changed files with 60 additions and 13 deletions
+35 -13
View File
@@ -2,6 +2,7 @@ const {SolveCaptcha, TWO_CAPTCHA_CONNECTION_FAILED} = require("./SolveCaptcha");
const ReserveResultPojo = require("../models/ReserveResultPojo");
const BlackListContactPojo = require("../models/BlackListContactPojo");
const appointmentLogger = require("../utiles/LoggerUtils")
const OCRResult = require("../models/OCRResult");
const PublishType = require("../models/PublishType");
const puppeteer = require('puppeteer');
@@ -88,15 +89,29 @@ class CommandorPage {
}
async connect_to_browser(){
async connect_to_browser(ocrResult) {
this.browser = await puppeteer.connect({
browserWSEndpoint: "ws://127.0.0.1:" + this.port + "/devtools/browser",
headless: false, defaultViewport: null
})
let pages = await this.browser.pages();
this.page = pages[pages.length - 1]
let content = await this.page.content()
console.log(content)
switch (ocrResult) {
case OCRResult.SUCCESS:
// get url and push to server
logWithDevice("will save success appointment", this.device)
await this.push_message_to_queue(PublishType.SUCCESS);
break;
case OCRResult.TO_REFRESH:
logWithDevice("will reload page", this.device)
await this.page.reload();
logWithDevice("will disconnect browser", this.device)
await this.browser.disconnect()
break;
}
let content = await this.page.content();
console.log(content);
}
async loadPage() {
@@ -348,18 +363,27 @@ class CommandorPage {
try {
// remove debug flag
// const validElement = await page.$('.btn');
console.log("will click on valid button")
console.log("will click on valid button")
console.log("will click on valid button")
this.page.evaluate(() => {
console.log("will click on valid button");
console.log("will click on valid button");
console.log("will click on valid button");
await this.page.evaluate(() => {
document.getElementsByClassName("btn")[0].click();
})
// this.browser.disconnect();
await delay(2000);
let ocrChecker = new OCRChecker(this.device, this.contact)
await ocrChecker.get_result()
// await delay(2000);
// let ocrChecker = new OCRChecker(this.device, this.contact);
// let checkResult = await ocrChecker.get_result();
// switch (checkResult) {
// case OCRResult.SUCCESS:
// // reconnect to page and get url
// await this.connect_to_browser(OCRResult.SUCCESS);
// break;
// case OCRResult.BLOCKED:
// await this.resetBrowser();
// break;
// }
} catch (e) {
log(e)
log(e);
}
}
}
@@ -656,8 +680,6 @@ class CommandorPage {
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