v3.6.1: no-v2ray launch pinning (strip proxy env, explicit --no-proxy-server / FF direct prefs), cross-platform browser discovery (Win/Linux/macOS incl. snap chromium), setup.mjs deploy self-check, README deploy docs

This commit is contained in:
2026-11-08 20:52:45 +03:30
parent 40f6737183
commit 19b0246828
4 changed files with 168 additions and 11 deletions
+43 -9
View File
@@ -89,31 +89,52 @@ const settingsSnapshot = () => ({
const DEFAULT_PORT = 9444;
const KIT_PROFILE = path.join(os.homedir(), '.dsh', 'browser-profiles', 'edge-kit');
// Real signed-in profiles per platform (Windows / Linux / macOS layouts).
const REAL_PROFILE = process.env.LOCALAPPDATA
? path.join(process.env.LOCALAPPDATA, 'Microsoft', 'Edge', 'User Data')
: process.platform === 'linux' ? path.join(os.homedir(), '.config', 'microsoft-edge')
: process.platform === 'darwin' ? path.join(os.homedir(), 'Library', 'Application Support', 'Microsoft Edge')
: null;
const CHROME_REAL_PROFILE = process.env.LOCALAPPDATA
? path.join(process.env.LOCALAPPDATA, 'Google', 'Chrome', 'User Data')
: process.platform === 'linux' ? path.join(os.homedir(), '.config', 'google-chrome')
: process.platform === 'darwin' ? path.join(os.homedir(), 'Library', 'Application Support', 'Google', 'Chrome')
: null;
const FF_PROFILES_ROOT = process.env.APPDATA
? path.join(process.env.APPDATA, 'Mozilla', 'Firefox', 'Profiles')
? path.join(process.env.APPDATA, 'Mozilla', 'Firefox')
: process.platform === 'linux' || process.platform === 'darwin' ? path.join(os.homedir(), '.mozilla', 'firefox')
: null;
const IS_WIN = process.platform === 'win32';
const BROWSER_CANDIDATES = {
edge: [
edge: IS_WIN ? [
'C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe',
'C:\\Program Files\\Microsoft\\Edge\\Application\\msedge.exe',
] : process.platform === 'darwin' ? [
'/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge',
] : [
'/opt/microsoft/msedge/msedge', '/usr/bin/microsoft-edge', '/usr/bin/microsoft-edge-stable', '/opt/edge/msedge',
],
chrome: [
chrome: IS_WIN ? [
'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
process.env.LOCALAPPDATA + '\\Google\\Chrome\\Application\\chrome.exe',
] : process.platform === 'darwin' ? [
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
] : [
'/opt/google/chrome/chrome', '/usr/bin/google-chrome', '/usr/bin/google-chrome-stable',
'/usr/bin/chromium', '/usr/bin/chromium-browser', '/snap/bin/chromium',
],
firefox: [
firefox: IS_WIN ? [
'C:\\Program Files\\Mozilla Firefox\\firefox.exe',
'C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe',
process.env.LOCALAPPDATA + '\\Mozilla Firefox\\firefox.exe',
] : process.platform === 'darwin' ? [
'/Applications/Firefox.app/Contents/MacOS/firefox',
] : [
'/usr/lib/firefox/firefox', '/usr/bin/firefox', '/snap/bin/firefox',
],
};
const kindOf = (exe) => /firefox/i.test(exe) ? 'firefox' : /chrome/i.test(exe) ? 'chrome' : 'edge';
const kindOf = (exe) => /firefox/i.test(exe) ? 'firefox' : /edge/i.test(exe) ? 'edge' : /chrom/i.test(exe) ? 'chrome' : 'edge';
// Firefox's real profile is whichever profiles.ini marks Default=1.
async function ffDefaultProfile() {
@@ -406,12 +427,17 @@ async function doLaunch(args) {
await fs.mkdir(profileDir, { recursive: true });
const headless = args.headless ?? cfgVal('headless', false);
const proxyFlag = await launchProxyFlag(args);
// The kit owns browser proxy state entirely: a system/v2ray proxy never
// leaks into the launched browser, and a proxy-less launch is explicit
// about going direct (--no-proxy-server / network.proxy.type=0).
const childEnv = { ...process.env };
for (const k of ['HTTP_PROXY', 'HTTPS_PROXY', 'ALL_PROXY', 'NO_PROXY', 'http_proxy', 'https_proxy', 'all_proxy', 'no_proxy']) delete childEnv[k];
const child = spawn(executable, kind === 'firefox' ? [
`-remote-debugging-port=${port}`,
'-profile', profileDir,
'-no-remote',
...(headless ? ['-headless'] : []),
...(proxyFlag ? ['-proxy-server', proxyFlag] : []),
...(proxyFlag ? ['-proxy-server', proxyFlag] : ['-preferences', '{"network.proxy.type":0}']),
'about:blank',
] : [
`--remote-debugging-port=${port}`,
@@ -424,9 +450,9 @@ async function doLaunch(args) {
'--disable-backgrounding-occluded-windows',
'--disable-renderer-backgrounding',
...(headless ? ['--headless=new'] : []),
...(proxyFlag ? [`--proxy-server=${proxyFlag}`] : []),
...(proxyFlag ? [`--proxy-server=${proxyFlag}`] : ['--no-proxy-server']),
'about:blank',
], { stdio: 'ignore', detached: false });
], { stdio: 'ignore', detached: false, env: childEnv });
if (!(await waitForPort(port, 25000))) {
child.kill();
throw new Error('browser started but the DevTools port never opened. If your everyday browser is running without a debug port it owns this profile: pass relaunch:true (closes it and reopens it debuggable), or use a different profileDir.');
@@ -573,7 +599,15 @@ function startChainServer(hops) {
const i = buf.indexOf('\r\n\r\n');
if (i < 0) { if (buf.length > 65536) client.destroy(); return; }
client.removeListener('data', onData);
handle(client, buf.slice(0, i), buf.slice(i + 4));
// A dead proxy hop makes chainTunnel throw inside handle(). Never leave
// that rejection floating: it surfaces as an unhandledRejection and the
// DSH host treats plugin errors as fatal load failures (crash 2026-11-08
// 20:31: proxy 34.43.46.91:80 CONNECT -> 503 took the whole host down).
// Fail only this browser connection instead.
void handle(client, buf.slice(0, i), buf.slice(i + 4)).catch(() => {
try { client.write('HTTP/1.1 502 Bad Gateway\r\nProxy-Chain: tunnel failed\r\nContent-Length: 0\r\nConnection: close\r\n\r\n'); } catch { /* gone */ }
try { client.destroy(); } catch { /* gone */ }
});
};
client.on('data', onData);
});