Merge pull request #268 from gnh1201/dev
Some checks are pending
CodeQL / Analyze (javascript) (push) Waiting to run

Introduce the accessor and improve the CDP protocol interface
This commit is contained in:
Namhyeon Go 2025-06-07 04:47:19 +09:00 committed by GitHub
commit a1eeb31070
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 81 additions and 40 deletions

View File

@ -14,15 +14,15 @@ var AutoIt = require("lib/autoit");
var Toolkit = require("lib/toolkit"); var Toolkit = require("lib/toolkit");
var ExtraMath = require("lib/extramath"); var ExtraMath = require("lib/extramath");
// for remote debugging // for Chromium-based browsers
var pageEventId = 0; var pageEventId = new STD.Accessor(0);
var publisherName = new STD.Accessor("chrome");
var ChromeObject = function() { var ChromeObject = function() {
STD.EventTarget.apply(this, arguments); // Set event-attachable object STD.EventTarget.apply(this, arguments); // Set event-attachable object
this.publisherName = "chrome"; this.workingDirectory = null;
this.workingDirectory = SYS.getEnvString("PROGRAMFILES") + "\\Google\\Chrome\\Application"; this.binPath = null;
this.binPath = SYS.getEnvString("PROGRAMFILES") + "\\Google\\Chrome\\Application\\chrome.exe";
this.profileName = "Default"; this.profileName = "Default";
this.userDataDir = null; this.userDataDir = null;
@ -34,7 +34,7 @@ var ChromeObject = function() {
"protocol": "socks5", "protocol": "socks5",
"host": "127.0.0.1", "host": "127.0.0.1",
"port": 1080, "port": 1080,
"ua": null "userAgent": null
}; };
this.inPrivate = false; this.inPrivate = false;
@ -63,6 +63,8 @@ var ChromeObject = function() {
this.oAutoIt = AutoIt.create(); this.oAutoIt = AutoIt.create();
this.baseScreenX = 1; this.baseScreenX = 1;
this.baseScreenY = (!this.isAppMode ? 84 : 32); this.baseScreenY = (!this.isAppMode ? 84 : 32);
this.setPublisherName(publisherName.get());
return this; return this;
}; };
@ -77,8 +79,11 @@ var ChromeObject = function() {
this.setProfile = function(profileName, installedDir) { this.setProfile = function(profileName, installedDir) {
this.profileName = (profileName == "Default" ? "Chrome" : profileName); this.profileName = (profileName == "Default" ? "Chrome" : profileName);
this.workingDirectory = this.workingDirectory.replace(":installedDir", installedDir); if (installedDir != null) {
this.binPath = this.binPath.replace(":installedDir", installedDir); this.installedDir = installedDir;
}
this.workingDirectory = this.workingDirectory.replace(":installedDir", this.installedDir);
this.binPath = this.binPath.replace(":installedDir", this.installedDir);
return this; return this;
}; };
@ -102,7 +107,7 @@ var ChromeObject = function() {
if (dirname != null) { if (dirname != null) {
this.userDataDir = dirname; this.userDataDir = dirname;
} else { } else {
this.userDataDir = SYS.getEnvString("APPDATA") + "\\WelsonJS\\" + this.publisherName + "_user_profile"; this.userDataDir = SYS.getEnvString("APPDATA") + "\\WelsonJS\\" + publisherName.get() + "_user_profile";
} }
return this; return this;
}; };
@ -188,7 +193,7 @@ var ChromeObject = function() {
cmd.push("\"--user-data-dir=" + this.userDataDir + "\""); cmd.push("\"--user-data-dir=" + this.userDataDir + "\"");
cmd.push("\"" + url + "\""); cmd.push("\"" + url + "\"");
SHELL.createShoutcut(this.publisherName + " (" + this.profileName + ")", cmd.join(' '), SYS.getCurrentScriptDirectory()); SHELL.createShoutcut(publisherName.get() + " (" + this.profileName + ")", cmd.join(' '), SYS.getCurrentScriptDirectory());
}; };
this.setInPrivate = function(flag) { this.setInPrivate = function(flag) {
@ -196,13 +201,13 @@ var ChromeObject = function() {
return this; return this;
}; };
this.setUserAgent = function(ua) { this.setUserAgent = function(userAgent) {
this.userAgent = ua; this.userAgent = userAgent;
return this; return this;
}; };
this.addUserAgent = function(ua) { this.addUserAgent = function(userAgent) {
this.userAgents.push(ua); this.userAgents.push(userAgent);
return this; return this;
}; };
@ -223,8 +228,7 @@ var ChromeObject = function() {
// if the file does not exists, Check the 32bit installation folder again // if the file does not exists, Check the 32bit installation folder again
if (!FILE.fileExists(this.binPath)) { if (!FILE.fileExists(this.binPath)) {
this.workingDirectory = SYS.getEnvString("PROGRAMFILES(X86)") + "\\Google\\:installedDir\\Application"; this.setPublisherName("chrome.x86");
this.binPath = SYS.getEnvString("PROGRAMFILES(X86)") + "\\Google\\:installedDir\\Application\\chrome.exe";
this.setProfile(this.profileName, this.installedDir); this.setProfile(this.profileName, this.installedDir);
} }
@ -282,8 +286,8 @@ var ChromeObject = function() {
if (this.proxy != null && this.isPreventProxy != true) { 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 + "\"");
if (this.proxy.ua != null) { if (this.proxy.userAgent != null) {
this.setUserAgent(this.proxy.ua); this.setUserAgent(this.proxy.userAgent);
} }
} }
@ -400,11 +404,11 @@ var ChromeObject = function() {
try { try {
if (this.pageId != "") { if (this.pageId != "") {
result = this.ws.send("ws://127.0.0.1:" + this.debuggingPort + "/devtools/page/" + this.pageId, JSON.stringify({ result = this.ws.send("ws://127.0.0.1:" + this.debuggingPort + "/devtools/page/" + this.pageId, JSON.stringify({
"id": pageEventId, "id": pageEventId.get(),
"method": method, "method": method,
"params": params "params": params
})); }));
pageEventId++; pageEventId.set(pageEventId.get() + 1);
console.log("ChromeObject().sendPageRPC() -> Sent"); console.log("ChromeObject().sendPageRPC() -> Sent");
} else { } else {
this.setPageId(null); this.setPageId(null);
@ -1246,12 +1250,14 @@ var ChromeObject = function() {
this.setVendor = function(vendor) { this.setVendor = function(vendor) {
this.setPublisherName(vendor); this.setPublisherName(vendor);
console.warn("Deprecated: Please use setPublisherName"); console.warn("Deprecated: Please use setPublisherName");
return this;
}; };
this.setPublisherName = function(publisherName) { this.setPublisherName = function(_publisherName) {
publisherName = publisherName.toLowerCase(); publisherName.set(_publisherName.toLowerCase());
switch (publisherName) { switch (publisherName.get()) {
case "msedge": case "msedge":
this.workingDirectory = SYS.getEnvString("PROGRAMFILES(X86)") + "\\Microsoft\\Edge\\Application"; this.workingDirectory = SYS.getEnvString("PROGRAMFILES(X86)") + "\\Microsoft\\Edge\\Application";
this.binPath = SYS.getEnvString("PROGRAMFILES(X86)") + "\\Microsoft\\Edge\\Application\\msedge.exe"; this.binPath = SYS.getEnvString("PROGRAMFILES(X86)") + "\\Microsoft\\Edge\\Application\\msedge.exe";
@ -1261,6 +1267,11 @@ var ChromeObject = function() {
this.workingDirectory = SYS.getEnvString("PROGRAMFILES") + "\\Google\\Chrome\\Application"; this.workingDirectory = SYS.getEnvString("PROGRAMFILES") + "\\Google\\Chrome\\Application";
this.binPath = SYS.getEnvString("PROGRAMFILES") + "\\Google\\:installedDir\\Application\\chrome.exe"; this.binPath = SYS.getEnvString("PROGRAMFILES") + "\\Google\\:installedDir\\Application\\chrome.exe";
break; break;
case "chrome.x86":
this.workingDirectory = SYS.getEnvString("PROGRAMFILES(X86)") + "\\Google\\Chrome\\Application";
this.binPath = SYS.getEnvString("PROGRAMFILES(X86)") + "\\Google\\:installedDir\\Application\\chrome.exe";
break;
case "chromium": case "chromium":
this.workingDirectory = SYS.getEnvString("LOCALAPPDATA") + "\\Chromium\\Application"; this.workingDirectory = SYS.getEnvString("LOCALAPPDATA") + "\\Chromium\\Application";
@ -1275,6 +1286,7 @@ var ChromeObject = function() {
case "whale": case "whale":
this.workingDirectory = SYS.getEnvString("PROGRAMFILES") + "\\Naver\\Naver Whale\\Application"; this.workingDirectory = SYS.getEnvString("PROGRAMFILES") + "\\Naver\\Naver Whale\\Application";
this.binPath = SYS.getEnvString("PROGRAMFILES") + "\\Naver\\Naver Whale\\Application\\whale.exe"; this.binPath = SYS.getEnvString("PROGRAMFILES") + "\\Naver\\Naver Whale\\Application\\whale.exe";
this.baseScreenY = 82;
break; break;
case "brave": case "brave":
@ -1414,7 +1426,7 @@ exports.startDebugInPrivate = function(url, proxy, profileName, debuggingPort, i
; ;
}; };
exports.VERSIONINFO = "Chrome Web Browser Debugging Interface (chrome.js) version 0.4.18"; exports.VERSIONINFO = "Chrome Web Browser Debugging Interface (chrome.js) version 0.4.20";
exports.AUTHOR = "abuse@catswords.net"; exports.AUTHOR = "abuse@catswords.net";
exports.global = global; exports.global = global;
exports.require = global.require; exports.require = global.require;

View File

@ -539,31 +539,59 @@ GeneratorFunction.Yield = function(message) {
GeneratorFunction.Yield.prototype = new Error(); GeneratorFunction.Yield.prototype = new Error();
GeneratorFunction.Yield.prototype.constructor = GeneratorFunction.Yield; GeneratorFunction.Yield.prototype.constructor = GeneratorFunction.Yield;
function StdStorage() { function StdAccessor(initialValue) {
this.data = {}; var value = initialValue;
this.length = 0;
this.commit = function() { this.get = function() {
this.length = Object.keys(data).length; return value;
}; };
this.key = function(idx) {
var keyName = Object.keys(data)[idx]; this.set = function(v) {
return data[keyName]; value = v;
}; };
}
StdAccessor.isAccessor = function(obj) {
return obj instanceof StdAccessor;
};
function StdStorage() {
var data = new StdAccessor({});
var length = new StdAccessor(0);
function commit() {
length.set(Object.keys(data.get()).length);
}
this.setItem = function(keyName, keyValue) { this.setItem = function(keyName, keyValue) {
data[keyName] = keyValue; var d = data.get();
this.commit(); d[keyName] = keyValue;
data.set(d);
commit();
}; };
this.getItem = function(keyName) { this.getItem = function(keyName) {
return data[keyName]; return data.get()[keyName];
}; };
this.removeItem = function(keyName) { this.removeItem = function(keyName) {
delete data[keyName]; var d = data.get();
this.commit(); delete d[keyName];
data.set(d);
commit();
}; };
this.clear = function() { this.clear = function() {
this.data = {}; data.set({});
this.commit(); commit();
};
this.key = function(idx) {
var d = data.get();
return Object.keys(d)[idx];
};
this.length = function() {
return length.get();
}; };
} }
@ -581,13 +609,14 @@ global.parseEnv = parseEnv;
exports.Event = StdEvent; exports.Event = StdEvent;
exports.EventTarget = StdEventTarget; exports.EventTarget = StdEventTarget;
exports.Accessor = StdAccessor;
exports.Storage = StdStorage; exports.Storage = StdStorage;
exports.alert = alert; exports.alert = alert;
exports.confirm = confirm; exports.confirm = confirm;
exports.prompt = prompt; exports.prompt = prompt;
exports.VERSIONINFO = "WelsonJS Standard Library (std.js) version 0.8.16"; exports.VERSIONINFO = "WelsonJS Standard Library (std.js) version 0.8.17";
exports.AUTHOR = "abuse@catswords.net"; exports.AUTHOR = "abuse@catswords.net";
exports.global = global; exports.global = global;
exports.require = global.require; exports.require = global.require;