This commit is contained in:
Namhyeon Go 2025-06-01 14:44:07 +09:00
parent 1a670b12c7
commit f2fe919ed0

View File

@ -2,7 +2,7 @@
// Chrome Web Browser Debugging Interface for WelsonJS framework // Chrome Web Browser Debugging Interface for WelsonJS framework
// Namhyeon Go <abuse@catswords.net> // Namhyeon Go <abuse@catswords.net>
// https://github.com/gnh1201/welsonjs // https://github.com/gnh1201/welsonjs
//
var STD = require("lib/std"); var STD = require("lib/std");
var RAND = require("lib/rand"); var RAND = require("lib/rand");
var SHELL = require("lib/shell"); var SHELL = require("lib/shell");
@ -20,12 +20,10 @@ var pageEventId = 0;
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.vendor = "Chrome"; this.publisherName = "chrome";
this.workingDirectory = SYS.getEnvString("PROGRAMFILES") + "\\Google\\:installedDir\\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\\Chrome\\Application\\chrome.exe";
//this.processID = 0;
this.installedDir = "Chrome";
this.profileName = "Default"; this.profileName = "Default";
this.userDataDir = null; this.userDataDir = null;
@ -78,10 +76,6 @@ 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.setInstalledDir(installedDir);
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; return this;
}; };
@ -91,7 +85,7 @@ var ChromeObject = function() {
try { try {
return FILE.deleteFolder(FN); return FILE.deleteFolder(FN);
} catch (e) { } catch (e) {
console.warn("Can not clear the session! Resaon: " + e.message); console.warn("Can not clear the session! " + e.message);
console.warn("Retrying clear the profile..."); console.warn("Retrying clear the profile...");
} }
} }
@ -105,14 +99,7 @@ var ChromeObject = function() {
if (dirname != null) { if (dirname != null) {
this.userDataDir = dirname; this.userDataDir = dirname;
} else { } else {
this.userDataDir = SHELL.getPathOfMyDocuments() + "\\UserData_Chrome_" + this.profileName; this.userDataDir = SYS.getEnvString("APPDATA") + "\\WelsonJS\\" + this.publisherName + "_user_profile";
}
return this;
};
this.setInstalledDir = function(dirname) {
if (dirname != null) {
this.installedDir = dirname;
} }
return this; return this;
}; };
@ -165,13 +152,13 @@ var ChromeObject = function() {
this.createShoutcut = function(url) { this.createShoutcut = function(url) {
if (!this.userDataDir) { if (!this.userDataDir) {
this.userDataDir = SHELL.getPathOfMyDocuments() + "\\UserData_Chrome_" + this.profileName; this.setUserDataDir(null);
} }
var cmd = [ var cmd = [
"cscript", "cscript",
"app.js", "app.js",
"shoutcut.legacy", "shoutcut",
"chrome", "chrome",
this.installedDir, this.installedDir,
]; ];
@ -198,11 +185,11 @@ var ChromeObject = function() {
cmd.push("--remote-debugging-port=" + this.debuggingPort); cmd.push("--remote-debugging-port=" + this.debuggingPort);
} }
cmd.push("--profile-directory=\"" + this.profileName + "\""); cmd.push("\"--profile-directory=" + this.profileName + "\"");
cmd.push("--user-data-dir=\"" + this.userDataDir + "\""); cmd.push("\"--user-data-dir=" + this.userDataDir + "\"");
cmd.push("\"" + url + "\""); cmd.push("\"" + url + "\"");
SHELL.createShoutcut("Chrome Prototype (" + this.installedDir + ")", cmd.join(' '), SYS.getCurrentScriptDirectory()); SHELL.createShoutcut("Chrome (" + this.installedDir + ")", cmd.join(' '), SYS.getCurrentScriptDirectory());
}; };
this.setInPrivate = function(flag) { this.setInPrivate = function(flag) {
@ -239,50 +226,19 @@ var ChromeObject = function() {
if (!FILE.fileExists(this.binPath)) { if (!FILE.fileExists(this.binPath)) {
this.workingDirectory = SYS.getEnvString("PROGRAMFILES(X86)") + "\\Google\\:installedDir\\Application"; this.workingDirectory = SYS.getEnvString("PROGRAMFILES(X86)") + "\\Google\\:installedDir\\Application";
this.binPath = SYS.getEnvString("PROGRAMFILES(X86)") + "\\Google\\:installedDir\\Application\\chrome.exe"; this.binPath = SYS.getEnvString("PROGRAMFILES(X86)") + "\\Google\\:installedDir\\Application\\chrome.exe";
this.setProfile(this.profileName, this.installedDir); this.setProfile(this.profileName);
} }
// find profile // find a executable file
if (!FILE.fileExists(this.binPath)) { if (!FILE.fileExists(this.binPath)) {
console.error("ChromeObject.open() -> '" + this.profileName + "' profile does not exists. You have to create it."); console.error("chrome.exe does not exists.");
return this; return this;
} }
// create shoutcut to desktop
if (this.debuggingPort == 0) {
this.createShoutcut();
}
/*
var process;
while (this.processID == 0) {
try {
if (!this.userDataDir) {
this.userDataDir = SHELL.getPathOfMyDocuments() + "\\UserData_Chrome_" + this.profileName;
}
var shell = SHELL.create().setWorkingDirectory(this.workingDirectory);
var process = shell.createProcess([
"\"" + this.binPath + "\"",
"--profile-directory=\"" + this.profileName + "\"",
"--proxy-server=\"socks5://127.0.0.1:" + this.proxyPort + "\"",
"--user-data-dir=\"" + this.userDataDir + "\"",
"\"" + url + "\""
].join(" "));
sleep(1500);
this.processID = process.ProcessID;
sleep(1500);
shell.release();
} catch (e) {
console.error("ChromeObject.open() ->", e.message);
sleep(1500);
}
}
*/
try { try {
// get user data directory // get user data directory
if (!this.userDataDir) { if (!this.userDataDir) {
this.userDataDir = SHELL.getPathOfMyDocuments() + "\\UserData_Chrome_" + this.profileName; this.setUserDataDir(null);
} }
// connect to shell // connect to shell
@ -321,7 +277,7 @@ var ChromeObject = function() {
//cmd.push("--restore-last-session"); //cmd.push("--restore-last-session");
// set profile directory // set profile directory
cmd.push("--profile-directory=\"" + this.profileName + "\""); cmd.push("\"--profile-directory=" + this.profileName + "\"");
// set proxy configuration // set proxy configuration
if (this.proxy != null && this.isPreventProxy != true) { if (this.proxy != null && this.isPreventProxy != true) {
@ -333,7 +289,7 @@ var ChromeObject = function() {
} }
// set user data directory // set user data directory
cmd.push("--user-data-dir=\"" + this.userDataDir + "\""); cmd.push("\"--user-data-dir=" + this.userDataDir + "\"");
// choice user agent // choice user agent
if (this.userAgent == null && this.userAgents.length > 0) { if (this.userAgent == null && this.userAgents.length > 0) {
@ -346,11 +302,7 @@ var ChromeObject = function() {
} }
// set the URL // set the URL
if (!this.isAppMode) { cmd.push((!this.isAppMode ? "\"" : "--app=\"") + url + "\"");
cmd.push("\"" + url + "\"");
} else {
cmd.push("--app=\"" + url + "\"");
}
// build the command line // build the command line
console.log(cmd.join(" ")); console.log(cmd.join(" "));
@ -362,7 +314,7 @@ var ChromeObject = function() {
// release shell // release shell
shell.release(); shell.release();
} catch (e) { } catch (e) {
console.error("ChromeObject.open() -> ", e.message); console.error(e.message, ", Error in ChromeObject.open()");
sleep(300); sleep(300);
} }
@ -374,28 +326,18 @@ var ChromeObject = function() {
if (this.debuggingPort > 0) { if (this.debuggingPort > 0) {
try { try {
//var responseText = HTTP.get("http://127.0.0.1:" + this.debuggingPort + "/json"); var responseText = HTTP.get("http://127.0.0.1:" + this.debuggingPort + "/json");
//console.log(responseText); var pageList = JSON.parse(responseText);
//pageList = JSON.parse(responseText);
this.pageList = pageList; // save the page list
var pageList = HTTP.create("CURL")
.setDataType("json")
.open("GET", "http://127.0.0.1:" + this.debuggingPort + "/json")
.send()
.responseBody
;
this.pageList = pageList;
return pageList;
} catch (e) { } catch (e) {
console.error("ChromeObject.getPageList() ->", e.message); console.error("ChromeObject.getPageList() ->", e.message);
//return this.getPageList(); // 무한 루프 문제로 주석처리
return pageList; // 바로 넘김
} }
} else { } else {
console.error("Remote debugging unavailable"); console.error("Remote debugging unavailable");
return pageList;
} }
return pageList;
}; };
this.getPageById = function(id) { this.getPageById = function(id) {
@ -1301,28 +1243,38 @@ var ChromeObject = function() {
return this.getEvaluatedValue('(confirm("' + s + '") ? "true" : "false")'); return this.getEvaluatedValue('(confirm("' + s + '") ? "true" : "false")');
}; };
this.setVendor = function(vendor) { this.setPublisherName = function(publisherName) {
var vendor = vendor.toLowerCase(); var publisherName = publisherName.toLowerCase();
switch (vendor) { switch (publisherName) {
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";
this.setUserDataDir(null);
break; break;
case "chrome": case "chrome":
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\\Chrome\\Application\\chrome.exe";
this.setUserDataDir(null);
break; break;
case "chromium": case "chromium":
this.workingDirectory = SYS.getEnvString("LOCALAPPDATA") + "\\Chromium\\Application"; this.workingDirectory = SYS.getEnvString("LOCALAPPDATA") + "\\Chromium\\Application";
this.binPath = SYS.getEnvString("LOCALAPPDATA") + "\\Chromium\\Application\\chrome.exe"; this.binPath = SYS.getEnvString("LOCALAPPDATA") + "\\Chromium\\Application\\chrome.exe";
this.setUserDataDir(null);
break; break;
case "opera": case "opera":
this.workingDirectory = SYS.getEnvString("LOCALAPPDATA") + "\\Programs\\Opera"; this.workingDirectory = SYS.getEnvString("LOCALAPPDATA") + "\\Programs\\Opera";
this.binPath = SYS.getEnvString("LOCALAPPDATA") + "\\Programs\\Opera\\opera.exe"; this.binPath = SYS.getEnvString("LOCALAPPDATA") + "\\Programs\\Opera\\opera.exe";
this.setUserDataDir(null);
break;
case "whale":
this.workingDirectory = SYS.getEnvString("PROGRAMFILES") + "\\Naver\\Naver Whale\\Application";
this.binPath = SYS.getEnvString("PROGRAMFILES") + "\\Naver\\Naver Whale\\Application\\whale.exe";
this.setUserDataDir(null);
break; break;
} }
@ -1448,7 +1400,7 @@ exports.startDebugInPrivate = function(url, proxy, profileName, debuggingPort, i
; ;
}; };
exports.VERSIONINFO = "Chrome Web Browser Debugging Interface (chrome.js) version 0.4.16"; exports.VERSIONINFO = "Chrome Web Browser Debugging Interface (chrome.js) version 0.4.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;