From 2e3ae53ab7f162e522d16f3ff89abd5cfa836950 Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Mon, 19 Jul 2021 23:31:59 +0900 Subject: [PATCH] Update chrome.js --- lib/chrome.js | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/lib/chrome.js b/lib/chrome.js index 9de3508..e1979ba 100644 --- a/lib/chrome.js +++ b/lib/chrome.js @@ -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; };