Update chrome.js

This commit is contained in:
Namhyeon Go 2021-07-19 23:31:59 +09:00 committed by GitHub
parent c04a3753e7
commit 2e3ae53ab7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -224,6 +224,8 @@ var ChromeObject = function() {
return JSON.parse(HTTP.get("http://127.0.0.1:" + this.debuggingPort + "/json"));
} catch (e) {
console.error("ChromeObject.getPageList() -> " + e.message);
sleep(1);
return this.getPageList();
}
} else {
console.error("Remote debugging unavailable");
@ -394,7 +396,7 @@ var ChromeObject = function() {
this.setTitle = function(title) {
if (this.debuggingPort > 0) {
for (var i = 0; i < 10; i++) {
for (var i = 0; i < 3; i++) {
this.evaluate('document.title = "' + title + '"');
}
}
@ -432,6 +434,19 @@ var ChromeObject = function() {
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
};
this.checkDebuggingPort = function() {
var isChecked = false;
if (this.debuggingPort > 0) {
var result = SHELL.exec("netstat -ano | findstr :" + this.debuggingPort);
if (result.indexOf(":" + this.debuggingPort) > -1) {
isChecked = true;
}
}
return isChecked;
};
this.create();
};
@ -450,11 +465,18 @@ exports.start = function(url, proxyPort, profileName, userDataDir, installedDir)
};
exports.startWithDebugging = function(url, proxy, profileName, debuggingPort) {
return (new ChromeObject())
.setProxy(proxy)
.setProfile(profileName, null)
.setUserDataDir(null)
.setDebuggingPort(debuggingPort)
.open(url)
var isChecked = false;
var browser = (new ChromeObject())
.setProxy(proxy)
.setProfile(profileName, null)
.setUserDataDir(null)
.setDebuggingPort(debuggingPort)
;
while (!isChecked) {
browser.open(url);
isChecked = browser.checkDebuggingPort();
}
return browser;
};