mirror of
https://github.com/stablyai/orca.git
synced 2026-10-08 00:02:38 +00:00
* fix(browser): apply the app-wide HTTP proxy to embedded browser sessions The proxy setting was only ever written to `session.defaultSession`, but browser guests run on their own `persist:orca-*` partitions. Any host reachable only via the configured proxy failed to load in an embedded tab, landing on `chrome-error://chromewebdata/`, while the same setting worked everywhere else. Adds a per-session applier alongside the existing defaultSession path, keyed by a WeakMap so one session's applied config can't suppress another's, and applies it to every browser partition through the single installer they all pass through. Startup awaits an explicit sweep so the first guest navigation can't race the installer's fire-and-forget write, and a settings change re-sweeps so toggling the proxy takes effect without a restart. Env-var fallback and the system-proxy probe mirror the defaultSession behaviour, so a browser partition resolves the proxy the same way the rest of the app does. Fixes STA-4779 * fix(browser): await per-session proxy readiness * fix(proxy): preserve loopback and authenticate * fix(proxy): settle browser partition update races * fix(proxy): close partition policy races * fix(proxy): order settings and release removed sessions * test(browser): await partition proxy readiness * fix(proxy): cancel removed partition retries * refactor(proxy): keep OpenCode rate limits out of scope * fix(proxy): preserve sessionless host policy * fix(proxy): gate requests on policy readiness * fix(proxy): retire deleted browser sessions * fix(proxy): close retired browser guests * fix(proxy): retain retired session guards * fix(proxy): retain retired partition policies * fix(browser): retry transient proxy application failures * fix(browser): release deleted partition installer state * fix(proxy): retry delayed transient failures * fix(proxy): preserve route session authority after rebase * fix(proxy): clear retired session credentials * fix(proxy): retire failed browser profiles * fix(proxy): harden failed session cleanup --------- Co-authored-by: Jinwoo-H <jinwoo0825@gmail.com>
69 lines
2.5 KiB
TypeScript
69 lines
2.5 KiB
TypeScript
import { session, type Session } from 'electron'
|
|
import type { BrowserSessionProfile } from '../../shared/browser-workspace-types'
|
|
import { applyProxySettingsToSession } from '../network/proxy-settings'
|
|
import type { NetworkProxySettings } from '../../shared/network-proxy'
|
|
|
|
// Why: browser modules hold no store handle, so main injects a reader the way rate-limits does.
|
|
let resolveNetworkProxySettings: (() => NetworkProxySettings) | null = null
|
|
let proxyPolicyGeneration = 0
|
|
// Why: removed partitions must stop stale readiness loops before their queued system release.
|
|
const browserSessionProxyApplicationGenerations = new WeakMap<Session, number>()
|
|
|
|
export function setBrowserNetworkProxySettingsResolver(
|
|
resolver: (() => NetworkProxySettings) | null
|
|
): void {
|
|
resolveNetworkProxySettings = resolver
|
|
if (!resolver) {
|
|
proxyPolicyGeneration = 0
|
|
}
|
|
}
|
|
|
|
export async function applyProxyToBrowserSession(sess: Session): Promise<void> {
|
|
const applicationGeneration = browserSessionProxyApplicationGenerations.get(sess) ?? 0
|
|
let observedGeneration: number
|
|
do {
|
|
observedGeneration = proxyPolicyGeneration
|
|
const resolved = resolveNetworkProxySettings?.()
|
|
if (!resolved) {
|
|
return
|
|
}
|
|
await applyProxySettingsToSession(sess, resolved)
|
|
} while (
|
|
applicationGeneration === (browserSessionProxyApplicationGenerations.get(sess) ?? 0) &&
|
|
observedGeneration !== proxyPolicyGeneration
|
|
)
|
|
}
|
|
|
|
export function invalidateBrowserSessionProxyApplication(sess: Session): void {
|
|
const generation = browserSessionProxyApplicationGenerations.get(sess) ?? 0
|
|
browserSessionProxyApplicationGenerations.set(sess, generation + 1)
|
|
}
|
|
|
|
/** Re-apply the app-wide proxy across every browser partition. */
|
|
export async function applyBrowserSessionProxies(
|
|
profiles: BrowserSessionProfile[],
|
|
settings?: NetworkProxySettings
|
|
): Promise<void> {
|
|
const resolved = settings ?? resolveNetworkProxySettings?.()
|
|
if (!resolved) {
|
|
return
|
|
}
|
|
proxyPolicyGeneration += 1
|
|
const failedPartitions = (
|
|
await Promise.all(
|
|
profiles.map(async (profile) => {
|
|
try {
|
|
await applyProxySettingsToSession(session.fromPartition(profile.partition), resolved)
|
|
return null
|
|
} catch {
|
|
console.warn('[proxy] Failed to apply proxy to browser partition', profile.partition)
|
|
return profile.partition
|
|
}
|
|
})
|
|
)
|
|
).filter((partition): partition is string => partition !== null)
|
|
if (failedPartitions.length > 0) {
|
|
throw new Error(`Failed to apply proxy to browser partitions: ${failedPartitions.join(', ')}`)
|
|
}
|
|
}
|