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