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 RAND = require("lib/rand");
var SHELL = require("lib/shell");
var SYS = require("lib/system");
var FILE = require("lib/file");
@ -23,6 +22,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",
@ -30,9 +32,9 @@ var ChromeObject = function() {
};
this.inPrivate = false;
// user agent
// user agent
this.userAgent = null;
this.userAgents = [];
this.userAgents = [];
// dependencies
this.oAutoIt = null;
@ -65,13 +67,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 +107,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);
@ -183,10 +186,21 @@ var ChromeObject = function() {
return this;
};
this.addUserAgent = function(ua) {
this.userAgents.push(ua);
return this;
};
this.addUserAgent = function(ua) {
this.userAgents.push(ua);
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 +288,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 + "\"");
}
@ -283,11 +297,11 @@ var ChromeObject = function() {
cmd.push("--user-data-dir=\"" + this.userDataDir + "\"");
// choice user agent
if (this.userAgents.length > 0) {
this.setUserAgent(RAND.one(this.userAgents));
}
if (this.userAgents.length > 0) {
this.setUserAgent(RAND.one(this.userAgents));
}
// set user agent
// set user agent
if (this.userAgent != null) {
cmd.push("--user-agent=\"" + this.userAgent + "\"");
}
@ -457,7 +471,6 @@ var ChromeObject = function() {
};
this.exit = function() {
console.log("exit");
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.require = global.require;