Update chrome.js

This commit is contained in:
Namhyeon Go 2022-01-10 02:41:57 +09:00 committed by GitHub
parent 91712498ad
commit 5e5f088dbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,6 +23,9 @@ var ChromeObject = function() {
this.installedDir = "Chrome";
this.profileName = "Default";
this.userDataDir = null;
// proxy
this.isPreventProxy = false;
this.proxy = {
"protocol": "socks5",
"host": "127.0.0.1",
@ -65,13 +68,9 @@ var ChromeObject = function() {
return this;
};
this.clear = function() {
console.log("clear");
return FILE.deleteFolder(SHELL.getPathOfMyDocuments() + "\\UserData_Chrome_" + this.profileName + "\\" + this.profileName);
};
this.clearProfile = function() {
return this.clear();
var FN = SHELL.getPathOfMyDocuments() + "\\UserData_Chrome_" + this.profileName + "\\" + this.profileName;
return FILE.deleteFolder(FN);
};
this.setUserDataDir = function(dirname) {
@ -109,7 +108,12 @@ var ChromeObject = function() {
this.proxy.port = port;
return this;
};
this.setIsPreventProxy = function(flag) {
this.isPreventProxy = flag;
return this;
};
this.setDebuggingPort = function(port) {
this.debuggingPort = port;
console.log("Enabled debugging port:", port);
@ -188,6 +192,17 @@ var ChromeObject = function() {
return this;
};
this.addUserAgentsFromFile = function(filename) {
var text = FILE.readFile(filename, "utf-8");
var lines = text.split(/\r?\n/);
for (var i = 0; i < lines.length; i++) {
if (lines[i].trim() !== "") {
this.userAgents.push(lines[i]);
}
}
return this;
};
this.open = function(url) {
this.setProfile(this.profileName, this.installedDir);
@ -274,7 +289,7 @@ var ChromeObject = function() {
cmd.push("--profile-directory=\"" + this.profileName + "\"");
// set proxy configuration
if (this.proxy != null) {
if (this.proxy != null && this.isPreventProxy != true) {
console.log("Enabled proxy server:", this.proxy.protocol + "://" + this.proxy.host + ":" + this.proxy.port);
cmd.push("--proxy-server=\"" + this.proxy.protocol + "://" + this.proxy.host + ":" + this.proxy.port + "\"");
}
@ -294,6 +309,7 @@ var ChromeObject = function() {
// set URL
cmd.push("\"" + url + "\"");
console.log(cmd.join(" "));
// run
shell.runAs(this.binPath, cmd);
@ -457,7 +473,6 @@ var ChromeObject = function() {
};
this.exit = function() {
console.log("exit");
return this.sendPageRPC("Browser.close", {});
};
@ -1117,6 +1132,20 @@ exports.startWithDebugging = function(url, proxy, profileName, debuggingPort) {
;
};
exports.VERSIONINFO = "Chrome Web Browser Debugging Interface (chrome.js) version 0.1";
exports.startDebug = function(url, proxy, profileName, debuggingPort, isPreventProxy) {
return (new ChromeObject())
.setProxy(proxy)
.setProfile(profileName, null)
.setUserDataDir(null)
.setDebuggingPort(debuggingPort)
.setIsPreventProxy(isPreventProxy)
.addUserAgentsFromFile("data\\Chrome.txt")
.addUserAgentsFromFile("data\\Edge.txt")
.addUserAgentsFromFile("data\\Safari.txt")
.open(url)
;
};
exports.VERSIONINFO = "Chrome Web Browser Debugging Interface (chrome.js) version 0.2";
exports.global = global;
exports.require = global.require;