Update chrome.js

This commit is contained in:
Namhyeon Go 2022-01-10 02:19:41 +09:00 committed by GitHub
parent 2776c57602
commit 357c45fc05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,7 +3,6 @@
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
var STD = require("lib/std"); var STD = require("lib/std");
var RAND = require("lib/rand");
var SHELL = require("lib/shell"); var SHELL = require("lib/shell");
var SYS = require("lib/system"); var SYS = require("lib/system");
var FILE = require("lib/file"); var FILE = require("lib/file");
@ -23,6 +22,9 @@ var ChromeObject = function() {
this.installedDir = "Chrome"; this.installedDir = "Chrome";
this.profileName = "Default"; this.profileName = "Default";
this.userDataDir = null; this.userDataDir = null;
// proxy
this.isPreventProxy = false;
this.proxy = { this.proxy = {
"protocol": "socks5", "protocol": "socks5",
"host": "127.0.0.1", "host": "127.0.0.1",
@ -30,9 +32,9 @@ var ChromeObject = function() {
}; };
this.inPrivate = false; this.inPrivate = false;
// user agent // user agent
this.userAgent = null; this.userAgent = null;
this.userAgents = []; this.userAgents = [];
// dependencies // dependencies
this.oAutoIt = null; this.oAutoIt = null;
@ -65,13 +67,9 @@ var ChromeObject = function() {
return this; return this;
}; };
this.clear = function() {
console.log("clear");
return FILE.deleteFolder(SHELL.getPathOfMyDocuments() + "\\UserData_Chrome_" + this.profileName + "\\" + this.profileName);
};
this.clearProfile = function() { this.clearProfile = function() {
return this.clear(); var FN = SHELL.getPathOfMyDocuments() + "\\UserData_Chrome_" + this.profileName + "\\" + this.profileName;
return FILE.deleteFolder(FN);
}; };
this.setUserDataDir = function(dirname) { this.setUserDataDir = function(dirname) {
@ -109,7 +107,12 @@ var ChromeObject = function() {
this.proxy.port = port; this.proxy.port = port;
return this; return this;
}; };
this.setIsPreventProxy = function(flag) {
this.isPreventProxy = flag;
return this;
};
this.setDebuggingPort = function(port) { this.setDebuggingPort = function(port) {
this.debuggingPort = port; this.debuggingPort = port;
console.log("Enabled debugging port:", port); console.log("Enabled debugging port:", port);
@ -183,10 +186,21 @@ var ChromeObject = function() {
return this; return this;
}; };
this.addUserAgent = function(ua) { this.addUserAgent = function(ua) {
this.userAgents.push(ua); this.userAgents.push(ua);
return this; 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.open = function(url) {
this.setProfile(this.profileName, this.installedDir); this.setProfile(this.profileName, this.installedDir);
@ -274,7 +288,7 @@ var ChromeObject = function() {
cmd.push("--profile-directory=\"" + this.profileName + "\""); cmd.push("--profile-directory=\"" + this.profileName + "\"");
// set proxy configuration // 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); 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 + "\""); cmd.push("--proxy-server=\"" + this.proxy.protocol + "://" + this.proxy.host + ":" + this.proxy.port + "\"");
} }
@ -283,11 +297,11 @@ var ChromeObject = function() {
cmd.push("--user-data-dir=\"" + this.userDataDir + "\""); cmd.push("--user-data-dir=\"" + this.userDataDir + "\"");
// choice user agent // choice user agent
if (this.userAgents.length > 0) { if (this.userAgents.length > 0) {
this.setUserAgent(RAND.one(this.userAgents)); this.setUserAgent(RAND.one(this.userAgents));
} }
// set user agent // set user agent
if (this.userAgent != null) { if (this.userAgent != null) {
cmd.push("--user-agent=\"" + this.userAgent + "\""); cmd.push("--user-agent=\"" + this.userAgent + "\"");
} }
@ -457,7 +471,6 @@ var ChromeObject = function() {
}; };
this.exit = function() { this.exit = function() {
console.log("exit");
return this.sendPageRPC("Browser.close", {}); return this.sendPageRPC("Browser.close", {});
}; };
@ -1117,6 +1130,17 @@ 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)
.open(url)
;
};
exports.VERSIONINFO = "Chrome Web Browser Debugging Interface (chrome.js) version 0.2";
exports.global = global; exports.global = global;
exports.require = global.require; exports.require = global.require;