Update chrome.js

This commit is contained in:
Namhyeon Go 2021-07-05 20:09:01 +09:00 committed by GitHub
parent 7b6bfce156
commit bdb5141bf8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,12 +23,21 @@ var ChromeObject = function() {
"port": 1080 "port": 1080
}; };
this.inPrivate = false; this.inPrivate = false;
this.oAutoIt = null;
// for remote debugging // for remote debugging
this.debuggingPort = 0; this.debuggingPort = 0;
this.pageId = ""; this.pageId = "";
this.ws = Websocket.create(); 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.setBinPath = function(path) {
this.binPath = path; this.binPath = path;
return this; return this;
@ -190,7 +199,8 @@ var ChromeObject = function() {
cmd.push("--profile-directory=\"" + this.profileName + "\""); cmd.push("--profile-directory=\"" + this.profileName + "\"");
if (this.proxy != null) { 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 + "\""); cmd.push("--user-data-dir=\"" + this.userDataDir + "\"");
@ -288,11 +298,15 @@ var ChromeObject = function() {
this.focus = function() { this.focus = function() {
if (this.debuggingPort > 0) { if (this.debuggingPort > 0) {
try { 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(); var pageList = this.getPageList();
for (var i = 0; i < pageList.length; i++) { for (var i = 0; i < pageList.length; i++) {
if (pageList[i].id == this.pageId) { if (pageList[i].id == this.pageId) {
oAutoIt.WinActivate(pageList[i].title); this.oAutoIt.WinActivate(pageList[i].title);
} }
} }
} catch (e) { } catch (e) {
@ -305,6 +319,59 @@ var ChromeObject = function() {
return this.evaluate("window.blur()"); 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() { exports.create = function() {