fix(web-probe): enforce browser no-proxy launch (#641)
Co-authored-by: Codex <codex@noreply.local>
This commit is contained in:
@@ -22,6 +22,7 @@ const screenshotIntervalMs = positiveInteger(process.env.UNIDESK_WEB_OBSERVE_SCR
|
||||
const maxSamples = positiveInteger(process.env.UNIDESK_WEB_OBSERVE_MAX_SAMPLES, 0);
|
||||
const viewport = parseViewport(process.env.UNIDESK_WEB_OBSERVE_VIEWPORT || "1440x900");
|
||||
const playwrightProxy = proxyConfigFromEnv(baseUrl);
|
||||
const chromiumLaunchOptions = chromiumLaunchOptionsForProxy(playwrightProxy);
|
||||
const pageId = "page-" + randomBytes(4).toString("hex");
|
||||
const dirs = {
|
||||
commandsPending: path.join(stateDir, "commands", "pending"),
|
||||
@@ -63,7 +64,7 @@ try {
|
||||
await writeHeartbeat({ status: "starting" });
|
||||
const launcher = await import(pathToFileURL(path.resolve("scripts/src/browser-launcher.mjs")).href);
|
||||
const { chromium } = await launcher.importPlaywright();
|
||||
browser = await launcher.launchChromium(chromium);
|
||||
browser = await launcher.launchChromium(chromium, chromiumLaunchOptions);
|
||||
context = await browser.newContext({ viewport, ...(playwrightProxy === null ? {} : { proxy: playwrightProxy }) });
|
||||
auth = await runControlCommand({ id: "startup-login", type: "login", createdAt: startedAt, source: "startup" }, async () => authenticate(context));
|
||||
page = await context.newPage();
|
||||
@@ -301,6 +302,21 @@ function proxyConfigFromEnv(targetBaseUrl) {
|
||||
return { server: raw };
|
||||
}
|
||||
|
||||
function chromiumLaunchOptionsForProxy(proxy) {
|
||||
const base = { env: browserProcessEnvWithoutProxy() };
|
||||
if (proxy === null) return { ...base, args: ["--no-proxy-server"] };
|
||||
return { ...base, proxy };
|
||||
}
|
||||
|
||||
function browserProcessEnvWithoutProxy() {
|
||||
const blocked = new Set(["HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY", "NO_PROXY", "http_proxy", "https_proxy", "all_proxy", "no_proxy"]);
|
||||
const env = {};
|
||||
for (const [key, value] of Object.entries(process.env)) {
|
||||
if (!blocked.has(key) && value !== undefined) env[key] = value;
|
||||
}
|
||||
return env;
|
||||
}
|
||||
|
||||
function noProxyMatches(hostname, rawList) {
|
||||
const host = String(hostname || "").toLowerCase();
|
||||
if (!host) return false;
|
||||
@@ -324,6 +340,11 @@ function publicNetwork(proxy) {
|
||||
server: publicProxyServer(proxy.server),
|
||||
valuesRedacted: true,
|
||||
},
|
||||
browser: {
|
||||
proxyMode: proxy === null ? "direct-no-proxy-server" : "explicit-playwright-proxy",
|
||||
proxyEnvCleared: true,
|
||||
valuesRedacted: true,
|
||||
},
|
||||
valuesRedacted: true,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user