mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-06-18 02:59:04 +00:00
Update chrome.js
This commit is contained in:
parent
7b6bfce156
commit
bdb5141bf8
|
@ -23,12 +23,21 @@ var ChromeObject = function() {
|
|||
"port": 1080
|
||||
};
|
||||
this.inPrivate = false;
|
||||
|
||||
this.oAutoIt = null;
|
||||
|
||||
// for remote debugging
|
||||
this.debuggingPort = 0;
|
||||
this.pageId = "";
|
||||
this.ws = Websocket.create();
|
||||
|
||||
this.create = function() {
|
||||
try {
|
||||
this.oAutoIt = CreateObject("AutoItX3.Control");
|
||||
} catch (e) {
|
||||
console.log("ChromeObject.create() -> " + e.message);
|
||||
}
|
||||
};
|
||||
|
||||
this.setBinPath = function(path) {
|
||||
this.binPath = path;
|
||||
return this;
|
||||
|
@ -190,7 +199,8 @@ var ChromeObject = function() {
|
|||
cmd.push("--profile-directory=\"" + this.profileName + "\"");
|
||||
|
||||
if (this.proxy != null) {
|
||||
cmd.push("--proxy-server=\"" + this.proxy.protocol + "://" + this.proxy.host + ":" + this.proxyPort + "\"");
|
||||
console.log("--proxy-server=\"" + this.proxy.protocol + "://" + this.proxy.host + ":" + this.proxy.port + "\"");
|
||||
cmd.push("--proxy-server=\"" + this.proxy.protocol + "://" + this.proxy.host + ":" + this.proxy.port + "\"");
|
||||
}
|
||||
|
||||
cmd.push("--user-data-dir=\"" + this.userDataDir + "\"");
|
||||
|
@ -288,11 +298,15 @@ var ChromeObject = function() {
|
|||
this.focus = function() {
|
||||
if (this.debuggingPort > 0) {
|
||||
try {
|
||||
var oAutoIt = CreateObject("AutoItX3.Control");
|
||||
// change webpage title for focusing window
|
||||
this.setTitle(this.pageId);
|
||||
sleep(1500);
|
||||
|
||||
// find window by title
|
||||
var pageList = this.getPageList();
|
||||
for (var i = 0; i < pageList.length; i++) {
|
||||
if (pageList[i].id == this.pageId) {
|
||||
oAutoIt.WinActivate(pageList[i].title);
|
||||
this.oAutoIt.WinActivate(pageList[i].title);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
|
@ -305,6 +319,59 @@ var ChromeObject = function() {
|
|||
return this.evaluate("window.blur()");
|
||||
};
|
||||
|
||||
this.downMouseWheel = function(times) {
|
||||
if (this.debuggingPort > 0) {
|
||||
try {
|
||||
var pos = this.getScreenPosition();
|
||||
this.oAutoIt.MouseMove(pos.x + 100, pos.y + 100);
|
||||
this.oAutoIt.MouseWheel("down", times);
|
||||
} catch (e) {
|
||||
console.error("ChromeObject.downMouseWheel() -> " + e.message);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.upMouseWheel = function(times) {
|
||||
if (this.debuggingPort > 0) {
|
||||
try {
|
||||
var pos = this.getScreenPosition();
|
||||
this.oAutoIt.MouseMove(pos.x + 100, pos.y + 100);
|
||||
this.oAutoIt.MouseWheel("up", times);
|
||||
} catch (e) {
|
||||
console.error("ChromeObject.upMouseWheel() -> " + e.message);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.setTitle = function(title) {
|
||||
if (this.debuggingPort > 0) {
|
||||
this.evaluate('document.title = "' + title + ' " + document.title');
|
||||
}
|
||||
};
|
||||
|
||||
this.getScreenPosition = function() {
|
||||
var response = this.evaluate('(function() { return [window.screenX, window.screenY].join(","); })();');
|
||||
var result = JSON.parse(response).result.result.value;
|
||||
var pos = result.split(',');
|
||||
return {
|
||||
"x": parseInt(pos[0]),
|
||||
"y": parseInt(pos[1])
|
||||
};
|
||||
};
|
||||
|
||||
this.getPageHeight = function() {
|
||||
var height = 0;
|
||||
|
||||
if (this.debuggingPort > 0) {
|
||||
var response = this.evaluate('(function(obj) { return Math.max(obj.scrollHeight, obj.clientHeight); })(document.querySelector("html"))');
|
||||
var result = JSON.parse(response).result.result.value;
|
||||
height = parseInt(result);
|
||||
}
|
||||
|
||||
return height;
|
||||
};
|
||||
|
||||
this.create();
|
||||
};
|
||||
|
||||
exports.create = function() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user