save browser ua
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
const {_android: android} = require('playwright');
|
|
||||||
const ExcelUtil = require("./excel/ExcelUtil");
|
const ExcelUtil = require("./excel/ExcelUtil");
|
||||||
const CommandorPage = require("./workers/CommandorPage");
|
const CommandorPage = require("./workers/CommandorPage");
|
||||||
const {MongoManager, formatDate} = require("./workers/mongo_manager");
|
const {MongoManager, formatDate} = require("./workers/mongo_manager");
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ class ReserveResultPojo {
|
|||||||
this.hostName = hostName
|
this.hostName = hostName
|
||||||
this.currentIp = ""
|
this.currentIp = ""
|
||||||
this.created_at = new Date().toLocaleString()
|
this.created_at = new Date().toLocaleString()
|
||||||
|
this.browserInfo = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
to_mongo_dict() {
|
to_mongo_dict() {
|
||||||
@@ -35,7 +36,8 @@ class ReserveResultPojo {
|
|||||||
serial: this.serial,
|
serial: this.serial,
|
||||||
created_at: this.created_at,
|
created_at: this.created_at,
|
||||||
hostName: this.hostName,
|
hostName: this.hostName,
|
||||||
current_ip: this.currentIp
|
current_ip: this.currentIp,
|
||||||
|
browserInfo: this.browserInfo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -773,11 +773,30 @@ class CommandorPage {
|
|||||||
if (url === "https://rendezvousparis.hermes.com/client/welcome") {
|
if (url === "https://rendezvousparis.hermes.com/client/welcome") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
let browserInfo = await this.page.evaluate(() => {
|
||||||
|
const ua = navigator.userAgent;
|
||||||
|
return ua
|
||||||
|
// let tem;
|
||||||
|
// let M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
|
||||||
|
// if (/trident/i.test(M[1])) {
|
||||||
|
// tem = /\brv[ :]+(\d+)/g.exec(ua) || [];
|
||||||
|
// return 'IE ' + (tem[1] || '');
|
||||||
|
// }
|
||||||
|
// if (M[1] === 'Chrome') {
|
||||||
|
// tem = ua.match(/\b(OPR|Edge)\/(\d+)/);
|
||||||
|
// if (tem != null) return tem.slice(1).join(' ').replace('OPR', 'Opera');
|
||||||
|
// }
|
||||||
|
// M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, '-?'];
|
||||||
|
// if ((tem = ua.match(/version\/(\d+)/i)) != null) M.splice(1, 1, tem[1]);
|
||||||
|
// return M.join(' ');
|
||||||
|
})
|
||||||
|
console.log(browserInfo); // outputs: `Chrome 62`
|
||||||
// save to mongoDb
|
// save to mongoDb
|
||||||
let reserve = ReserveResultPojo.create_from_contact(this.contact, id, url, this.choosedStore, publishType);
|
let reserve = ReserveResultPojo.create_from_contact(this.contact, id, url, this.choosedStore, publishType);
|
||||||
reserve.source_from = this.device.model;
|
reserve.source_from = this.device.model;
|
||||||
reserve.currentIp = currentIp
|
reserve.currentIp = currentIp
|
||||||
reserve.serial = this.device.serial;
|
reserve.serial = this.device.serial;
|
||||||
|
reserve.browserInfo = browserInfo;
|
||||||
await this.mongoManager.saveReserveToDb(reserve.to_mongo_dict())
|
await this.mongoManager.saveReserveToDb(reserve.to_mongo_dict())
|
||||||
if (!this.page.isClosed()) {
|
if (!this.page.isClosed()) {
|
||||||
try {
|
try {
|
||||||
@@ -841,7 +860,7 @@ class CommandorPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async connectBrowserIfNecessary() {
|
async connectBrowserIfNecessary() {
|
||||||
if (this.browser == undefined || !this.browser.isConnected()) {
|
if (this.browser === undefined || !this.browser.isConnected()) {
|
||||||
try {
|
try {
|
||||||
this.browser = await puppeteer.connect({
|
this.browser = await puppeteer.connect({
|
||||||
browserWSEndpoint: "ws://127.0.0.1:" + this.port + "/devtools/browser",
|
browserWSEndpoint: "ws://127.0.0.1:" + this.port + "/devtools/browser",
|
||||||
@@ -893,10 +912,6 @@ class CommandorPage {
|
|||||||
await this.checkResultWithOcr()
|
await this.checkResultWithOcr()
|
||||||
} else {
|
} else {
|
||||||
await this.checkResultWithOcr()
|
await this.checkResultWithOcr()
|
||||||
// if (checkResult === OCRResult.SLIDING_CAPTCHA) {
|
|
||||||
// checkResult = OCRResult.TERMINAED
|
|
||||||
// this.isTerminated = true
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// await delay(5 * 1000)
|
// await delay(5 * 1000)
|
||||||
|
|||||||
Reference in New Issue
Block a user