mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-11 20:21:03 +00:00
Update chrome.js
This commit is contained in:
parent
3450a3124a
commit
19957e12b7
|
@ -30,6 +30,7 @@ var ChromeObject = function() {
|
|||
this.pageId = "";
|
||||
this.ws = Websocket.create();
|
||||
this.isAttached = false;
|
||||
this.pageList = [];
|
||||
|
||||
this.create = function() {
|
||||
try {
|
||||
|
@ -89,8 +90,9 @@ var ChromeObject = function() {
|
|||
return this;
|
||||
};
|
||||
|
||||
this.setDebuggingPort = function(n) {
|
||||
this.debuggingPort = (typeof(n) !== "number" ? this.debuggingPort : n);
|
||||
this.setDebuggingPort = function(port) {
|
||||
this.debuggingPort = port;
|
||||
console.log("Debugging port setted: " + port);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -219,17 +221,20 @@ var ChromeObject = function() {
|
|||
};
|
||||
|
||||
this.getPageList = function() {
|
||||
var pageList = [];
|
||||
|
||||
if (this.debuggingPort > 0) {
|
||||
try {
|
||||
return JSON.parse(HTTP.get("http://127.0.0.1:" + this.debuggingPort + "/json"));
|
||||
pageList = JSON.parse(HTTP.get("http://127.0.0.1:" + this.debuggingPort + "/json"));
|
||||
this.pageList = pageList;
|
||||
return pageList;
|
||||
} catch (e) {
|
||||
console.error("ChromeObject.getPageList() -> " + e.message);
|
||||
sleep(1);
|
||||
return this.getPageList();
|
||||
}
|
||||
} else {
|
||||
console.error("Remote debugging unavailable");
|
||||
return [];
|
||||
return pageList;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -303,7 +308,7 @@ var ChromeObject = function() {
|
|||
};
|
||||
|
||||
this.terminate = function() {
|
||||
var pageList = this.getPageList();
|
||||
var pageList = this.pageList;
|
||||
for (var i = 0; i < pageList.length; i++) {
|
||||
this.oAutoIt.WinKill(pageList[i].title);
|
||||
}
|
||||
|
@ -402,6 +407,13 @@ var ChromeObject = function() {
|
|||
}
|
||||
};
|
||||
|
||||
this.getTitle = function() {
|
||||
if (this.debuggingPort > 0) {
|
||||
var response = this.evaluate('document.title');
|
||||
return JSON.parse(response).result.result.value;
|
||||
}
|
||||
};
|
||||
|
||||
this.getScreenPosition = function() {
|
||||
var response = this.evaluate('(function() { return [window.screenX, window.screenY].join(","); })();');
|
||||
var result = JSON.parse(response).result.result.value;
|
||||
|
@ -465,18 +477,11 @@ exports.start = function(url, proxyPort, profileName, userDataDir, installedDir)
|
|||
};
|
||||
|
||||
exports.startWithDebugging = function(url, proxy, profileName, debuggingPort) {
|
||||
var isChecked = false;
|
||||
var browser = (new ChromeObject())
|
||||
return (new ChromeObject())
|
||||
.setProxy(proxy)
|
||||
.setProfile(profileName, null)
|
||||
.setUserDataDir(null)
|
||||
.setDebuggingPort(debuggingPort)
|
||||
.open(url)
|
||||
;
|
||||
|
||||
while (!isChecked) {
|
||||
browser.open(url);
|
||||
isChecked = browser.checkDebuggingPort();
|
||||
}
|
||||
|
||||
return browser;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user