Update chrome.js

This commit is contained in:
Namhyeon Go 2021-06-20 05:51:34 +09:00 committed by GitHub
parent 29637a06b9
commit ce4003ec17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,17 +4,22 @@
var SHELL = require("lib/shell");
var SYS = require("lib/system");
var FILE = require("lib/file");
var HTTP = require("lib/http");
var ChromeObject = function() {
this.workingDirectory = SYS.getEnvString("PROGRAMFILES") + "\\Google\\Chrome\\Application";
this.binPath = SYS.getEnvString("PROGRAMFILES") + "\\Google\\:installedDir\\Application\\chrome.exe";
this.processID = 0;
//this.processID = 0;
this.installedDir = "Chrome";
this.profileName = "Default";
this.userDataDir = null;
this.proxyPort = 1080;
this.proxy = {
"protocol": "socks5",
"host": "127.0.0.1",
"port": 1080
};
this.inPrivate = false;
this.processList = [];
this.debuggingPort = 0;
this.setBinPath = function(path) {
this.binPath = path;
@ -24,9 +29,9 @@ var ChromeObject = function() {
this.setProfile = function(profileName, installedDir) {
this.profileName = (profileName == "Default" ? "Chrome" : profileName);
this.installedDir = installedDir;
//this.workingDirectory = this.workingDirectory.replace(":installedDir", this.installedDir);
//this.binPath = this.binPath.replace(":installedDir", this.installedDir);
this.binPath = this.binPath.replace(":installedDir", "Chrome");
this.workingDirectory = this.workingDirectory.replace(":installedDir", this.installedDir);
this.binPath = this.binPath.replace(":installedDir", this.installedDir);
//this.binPath = this.binPath.replace(":installedDir", "Chrome");
return this;
};
@ -40,44 +45,56 @@ var ChromeObject = function() {
return this;
};
this.setProxyPort = function(s) {
this.proxyPort = s;
this.setProxy = function(obj) {
this.proxy = obj;
return this;
};
this.getProcessList = function() {
return this.processList;
this.setProxyProtocol = function(s) {
this.proxy.protocol = s;
return this;
};
this.setProxyHost = function(s) {
this.proxy.host = s;
return this;
};
this.setProxyPort = function(n) {
this.proxy.port = n;
return this;
};
this.setDebuggingPort = function(n) {
this.debuggingPort = n;
}
this.createShoutcut = function(url) {
if (!this.userDataDir) {
this.userDataDir = SHELL.getPathOfMyDocuments() + "\\UserData_Chrome_" + this.profileName;
}
if (!this.inPrivate) {
SHELL.createDesktopIcon("Chrome Prototype (" + this.installedDir + ")", [
var cmd = [
"cscript",
"app.js",
"shoutcut",
"chrome",
this.installedDir,
"--profile-directory=\"" + this.profileName + "\"",
"--user-data-dir=\"" + this.userDataDir + "\"",
"\"" + url + "\""
].join(' '), SYS.getCurrentScriptDirectory());
} else {
SHELL.createDesktopIcon("Chrome Prototype (" + this.installedDir + ")", [
"cscript",
"app.js",
"shoutcut",
"chrome",
this.installedDir,
"--incognito",
"--profile-directory=\"" + this.profileName + "\"",
"--user-data-dir=\"" + this.userDataDir + "\"",
"\"" + url + "\""
].join(' '), SYS.getCurrentScriptDirectory());
];
if (this.inPrivate) {
cmd.push("--incognito");
}
if (this.debuggingPort > 0) {
cmd.push("--remote-debugging-port=" + this.debuggingPort);
}
cmd.push("--profile-directory=\"" + this.profileName + "\"");
cmd.push("--user-data-dir=\"" + this.userDataDir + "\"");
cmd.push("\"" + url + "\"");
SHELL.createDesktopIcon("Chrome Prototype (" + this.installedDir + ")", cmd.join(' '), SYS.getCurrentScriptDirectory());
};
this.setInPrivate = function(flag) {
@ -139,23 +156,21 @@ var ChromeObject = function() {
var shell = SHELL.create();
shell.setWorkingDirectory(this.workingDirectory);
if (!this.inPrivate) {
shell.runAs(this.binPath, [
"--profile-directory=\"" + this.profileName + "\"",
"--proxy-server=\"socks5://127.0.0.1:" + this.proxyPort + "\"",
"--user-data-dir=\"" + this.userDataDir + "\"",
"\"" + url + "\""
]);
} else {
shell.runAs(this.binPath, [
"--incognito",
"--profile-directory=\"" + this.profileName + "\"",
"--proxy-server=\"socks5://127.0.0.1:" + this.proxyPort + "\"",
"--user-data-dir=\"" + this.userDataDir + "\"",
"\"" + url + "\""
]);
var cmd = [];
if (this.inPrivate) {
cmd.push("--incognito");
}
if (this.debuggingPort > 0) {
cmd.push("--remote-debugging-port=" + this.debuggingPort);
}
cmd.push("--profile-directory=\"" + this.profileName + "\"");
cmd.push("--proxy-server=\"" + this.proxy.protocol + "://" + this.proxy.host + ":" + this.proxyPort + "\"");
cmd.push("--user-data-dir=\"" + this.userDataDir + "\"");
cmd.push("\"" + url + "\"");
sleep(1500);
shell.release();
} catch (e) {
@ -165,23 +180,56 @@ var ChromeObject = function() {
return this;
};
this.getPageList = function() {
if (this.debuggingPort > 0) {
return HTTP.get("http://localhost:" + this.debuggingPort + "/json");
} else {
console.error("Remote debugging unavailable");
return [];
}
};
this.getPageById = function(id) {
var pages = pageList.filter(function(x) {
return (pageList[k].id = id);
});
return (pages.length > 0 ? pages[0] : null);
};
this.getPagesByUrl = function(url) {
return pageList.filter(function(x) {
return (x.url == url);
});
};
this.getPagesByTitle = function(title) {
return pageList.filter(function(x) {
return (x.title == title);
});
};
};
exports.create = function() {
return new ChromeObject();
};
exports.getProcessIDs = function() {
return (new ChromeObject()).getProcessIDs();
};
exports.start = function(url, proxyPort, profileName, userDataDir, installedDir) {
return (new ChromeObject())
.setProxyPort(proxyPort)
.setProfile(profileName, installedDir)
.setUserDataDir(userDataDir)
.setInstalledDir(installedDir)
.open(url)
.processID
.open(url);
;
};
exports.startWithDebugging = function(url, proxy, profileName, userDataDir, installedDir, debuggingPort) {
return (new ChromeObject())
.setProxy(proxy)
.setProfile(profileName, installedDir)
.setUserDataDir(userDataDir)
.setInstalledDir(installedDir)
.setDebuggingPort(debuggingPort)
.open(url);
};