From e9c4f728836ea2609ab7805bb6058e93e58a6999 Mon Sep 17 00:00:00 2001 From: Draculabo Date: Sat, 11 Apr 2026 16:49:56 +0800 Subject: [PATCH] chore(debug): add proxyman proxy debugging tools --- .vscode/launch.json | 24 ++++ scripts/start-antigravity-with-proxyman.ps1 | 118 ++++++++++++++++++++ src/main.ts | 36 ++++++ 3 files changed, 178 insertions(+) create mode 100644 scripts/start-antigravity-with-proxyman.ps1 diff --git a/.vscode/launch.json b/.vscode/launch.json index a237049..e2feca8 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,6 +12,30 @@ "outFiles": ["${workspaceFolder}/.vite/build/**/*.js"], "console": "integratedTerminal", "autoAttachChildProcesses": true + }, + { + "name": "Debug Main Process (Proxyman)", + "type": "node", + "request": "launch", + "cwd": "${workspaceFolder}", + "runtimeExecutable": "cmd.exe", + "runtimeArgs": ["/c", "npm", "run", "start"], + "sourceMaps": true, + "outFiles": ["${workspaceFolder}/.vite/build/**/*.js"], + "console": "integratedTerminal", + "autoAttachChildProcesses": true, + "env": { + "NODE_USE_ENV_PROXY": "1", + "HTTP_PROXY": "http://127.0.0.1:9090", + "HTTPS_PROXY": "http://127.0.0.1:9090", + "ALL_PROXY": "http://127.0.0.1:9090", + "NO_PROXY": "localhost,127.0.0.1,::1", + "ELECTRON_PROXY_SERVER": "http://127.0.0.1:9090", + "ELECTRON_PROXY_BYPASS_LIST": ";localhost;127.0.0.1;::1", + "DEBUG_PROXY_TRACE": "1", + "NODE_EXTRA_CA_CERTS": "C:\\Users\\Administrator\\AppData\\Roaming\\Proxyman\\certificate\\certs\\ca.pem", + "NODE_TLS_REJECT_UNAUTHORIZED": "0" + } } ] } diff --git a/scripts/start-antigravity-with-proxyman.ps1 b/scripts/start-antigravity-with-proxyman.ps1 new file mode 100644 index 0000000..3dbe05a --- /dev/null +++ b/scripts/start-antigravity-with-proxyman.ps1 @@ -0,0 +1,118 @@ +# Starts the installed Antigravity app with Proxyman proxy settings for local debugging. +# +# Usage: +# powershell -ExecutionPolicy Bypass -File .\scripts\start-antigravity-with-proxyman.ps1 +# powershell -ExecutionPolicy Bypass -File .\scripts\start-antigravity-with-proxyman.ps1 -Port 9090 -AllowInsecureTls +# +# Notes: +# - This script is intended for local debugging only. +# - It terminates existing Antigravity processes first so the new environment variables take effect. + +[CmdletBinding()] +param( + [int]$Port = 9090, + [string]$ProxyHost = '127.0.0.1', + [string]$AppPath = 'C:\Users\Administrator\AppData\Local\Programs\Antigravity\Antigravity.exe', + [string]$CaPath = 'C:\Users\Administrator\AppData\Roaming\Proxyman\certificate\certs\ca.pem', + [string]$NoProxy = 'localhost,127.0.0.1,::1', + [switch]$AllowInsecureTls, + [switch]$KeepExisting +) + +$ErrorActionPreference = 'Stop' + +function Write-ColorLine { + param( + [string]$Color, + [string]$Message + ) + + Write-Host $Message -ForegroundColor $Color +} + +function Info { + param([string]$Message) + + Write-ColorLine -Color 'Cyan' -Message "[INFO] $Message" +} + +function Success { + param([string]$Message) + + Write-ColorLine -Color 'Green' -Message "[OK] $Message" +} + +function Warn { + param([string]$Message) + + Write-ColorLine -Color 'Yellow' -Message "[WARN] $Message" +} + +function Fail { + param([string]$Message) + + Write-ColorLine -Color 'Red' -Message "[ERROR] $Message" + exit 1 +} + +$proxyUrl = "http://${ProxyHost}:${Port}" +$proxyBypassList = ';localhost;127.0.0.1;::1' + +if (-not (Test-Path -LiteralPath $AppPath)) { + Fail "Antigravity executable not found: $AppPath" +} + +if (-not (Test-Path -LiteralPath $CaPath)) { + Fail "Proxyman CA file not found: $CaPath" +} + +Info "Proxy URL: $proxyUrl" +Info "Antigravity path: $AppPath" +Info "CA path: $CaPath" + +if (-not $KeepExisting) { + $existingProcesses = Get-Process -Name 'Antigravity' -ErrorAction SilentlyContinue + if ($existingProcesses) { + Warn "Stopping existing Antigravity processes so the new proxy environment takes effect..." + $existingProcesses | Stop-Process -Force + Start-Sleep -Milliseconds 800 + } else { + Info 'No running Antigravity process found.' + } +} else { + Warn 'KeepExisting enabled; existing Antigravity processes were not terminated.' +} + +$env:HTTP_PROXY = $proxyUrl +$env:HTTPS_PROXY = $proxyUrl +$env:ALL_PROXY = $proxyUrl +$env:NO_PROXY = $NoProxy +$env:ELECTRON_PROXY_SERVER = $proxyUrl +$env:ELECTRON_PROXY_BYPASS_LIST = $proxyBypassList +$env:NODE_EXTRA_CA_CERTS = $CaPath + +if ($AllowInsecureTls) { + $env:NODE_TLS_REJECT_UNAUTHORIZED = '0' + Warn 'NODE_TLS_REJECT_UNAUTHORIZED=0 is enabled for this launch. Use for debugging only.' +} else { + Remove-Item Env:NODE_TLS_REJECT_UNAUTHORIZED -ErrorAction SilentlyContinue +} + +Info 'Starting Antigravity with Proxyman proxy settings...' +$process = Start-Process -FilePath $AppPath -ArgumentList @( + "--proxy-server=$proxyUrl", + "--proxy-bypass-list=$proxyBypassList" +) -WorkingDirectory (Split-Path -Parent $AppPath) -PassThru + +Success "Antigravity started. PID: $($process.Id)" +Write-Host '' +Write-Host 'Environment used for this launch:' -ForegroundColor Gray +Write-Host " HTTP_PROXY=$($env:HTTP_PROXY)" -ForegroundColor Gray +Write-Host " HTTPS_PROXY=$($env:HTTPS_PROXY)" -ForegroundColor Gray +Write-Host " NO_PROXY=$($env:NO_PROXY)" -ForegroundColor Gray +Write-Host " NODE_EXTRA_CA_CERTS=$($env:NODE_EXTRA_CA_CERTS)" -ForegroundColor Gray +if ($AllowInsecureTls) { + Write-Host ' NODE_TLS_REJECT_UNAUTHORIZED=0' -ForegroundColor Gray +} +Write-Host '' +Write-Host 'If Proxyman still does not show traffic, verify that no older Antigravity instance is still alive.' -ForegroundColor Gray diff --git a/src/main.ts b/src/main.ts index a05a758..d5a0001 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,6 +4,7 @@ import type { MessageBoxOptions } from 'electron'; import path from 'path'; import fs from 'fs'; import squirrelStartup from 'electron-squirrel-startup'; +import { EnvHttpProxyAgent, setGlobalDispatcher } from 'undici'; import { ipcMain } from 'electron/main'; import { ipcContext } from '@/ipc/context'; @@ -57,6 +58,41 @@ if (squirrelStartup) { } const inDevelopment = process.env.NODE_ENV === 'development'; +const debugHttpProxy = process.env.http_proxy?.trim() || process.env.HTTP_PROXY?.trim(); +const debugHttpsProxy = process.env.https_proxy?.trim() || process.env.HTTPS_PROXY?.trim(); +const debugNoProxy = process.env.no_proxy?.trim() || process.env.NO_PROXY?.trim(); +const debugProxyServer = + process.env.ELECTRON_PROXY_SERVER?.trim() || debugHttpsProxy || debugHttpProxy; +const debugProxyBypassList = + process.env.ELECTRON_PROXY_BYPASS_LIST?.trim() || ';localhost;127.0.0.1;::1'; + +function configureDebugProxy() { + if (debugHttpProxy || debugHttpsProxy) { + setGlobalDispatcher( + new EnvHttpProxyAgent({ + httpProxy: debugHttpProxy, + httpsProxy: debugHttpsProxy, + noProxy: debugNoProxy, + }), + ); + logger.info( + `[Debug Proxy] Node fetch proxy enabled (http: ${debugHttpProxy ?? 'none'}, https: ${debugHttpsProxy ?? 'none'}, no_proxy: ${debugNoProxy ?? 'none'})`, + ); + } + + if (!debugProxyServer) { + return; + } + + // Route Chromium traffic through the local debug proxy while keeping local dev servers direct. + app.commandLine.appendSwitch('proxy-server', debugProxyServer); + app.commandLine.appendSwitch('proxy-bypass-list', debugProxyBypassList); + logger.info( + `[Debug Proxy] Electron proxy enabled: ${debugProxyServer} (bypass: ${debugProxyBypassList})`, + ); +} + +configureDebugProxy(); // Keep a global reference of the window object, if you don't, the window will // be closed automatically when the JavaScript object is garbage collected.