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