Merge pull request #266 from gnh1201/dev
Some checks failed
CodeQL / Analyze (javascript) (push) Has been cancelled

Fix #251 #246
This commit is contained in:
Namhyeon Go 2025-06-01 22:41:05 +09:00 committed by GitHub
commit 69c58e0e96
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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,14 +20,13 @@ 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;
this.installedDir = "Chrome";
// proxy // proxy
this.isPreventProxy = false; this.isPreventProxy = false;
@ -78,10 +77,8 @@ 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", installedDir);
this.workingDirectory = this.workingDirectory.replace(":installedDir", this.installedDir); this.binPath = this.binPath.replace(":installedDir", installedDir);
this.binPath = this.binPath.replace(":installedDir", this.installedDir);
//this.binPath = this.binPath.replace(":installedDir", "Chrome");
return this; return this;
}; };
@ -91,7 +88,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 +102,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,15 +155,11 @@ 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", this.binPath
"app.js",
"shoutcut.legacy",
"chrome",
this.installedDir,
]; ];
// disable default browser check // disable default browser check
@ -198,11 +184,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(this.publisherName + " (" + this.profileName + ")", cmd.join(' '), SYS.getCurrentScriptDirectory());
}; };
this.setInPrivate = function(flag) { this.setInPrivate = function(flag) {
@ -242,47 +228,16 @@ var ChromeObject = function() {
this.setProfile(this.profileName, this.installedDir); this.setProfile(this.profileName, this.installedDir);
} }
// 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 +276,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 +288,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) {
@ -342,15 +297,11 @@ var ChromeObject = function() {
// 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 + "\"");
} }
// 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 +313,7 @@ var ChromeObject = function() {
// release shell // release shell
shell.release(); shell.release();
} catch (e) { } catch (e) {
console.error("ChromeObject.open() -> ", e.message); console.error("Error opening a browser: " + e.message);
sleep(300); sleep(300);
} }
@ -374,28 +325,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); 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,10 +1242,16 @@ var ChromeObject = function() {
return this.getEvaluatedValue('(confirm("' + s + '") ? "true" : "false")'); return this.getEvaluatedValue('(confirm("' + s + '") ? "true" : "false")');
}; };
// @deprecated
this.setVendor = function(vendor) { this.setVendor = function(vendor) {
var vendor = vendor.toLowerCase(); this.setPublisherName(vendor);
console.warn("Deprecated: Please use setPublisherName");
};
switch (vendor) { this.setPublisherName = function(publisherName) {
publisherName = publisherName.toLowerCase();
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";
@ -1324,6 +1271,15 @@ var ChromeObject = function() {
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";
break; break;
case "whale":
this.workingDirectory = SYS.getEnvString("PROGRAMFILES") + "\\Naver\\Naver Whale\\Application";
this.binPath = SYS.getEnvString("PROGRAMFILES") + "\\Naver\\Naver Whale\\Application\\whale.exe";
break;
}
if (!this.userDataDir) {
this.setUserDataDir(null);
} }
return this; return this;
@ -1448,7 +1404,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;