Optimize gateway comms reload behavior and strengthen regression coverage (#496)

This commit is contained in:
Lingxuan Zuo
2026-03-15 20:36:48 +08:00
committed by GitHub
Unverified
parent 08960d700f
commit 1dbe4a8466
36 changed files with 1511 additions and 197 deletions

View File

@@ -129,6 +129,14 @@ function shouldFallbackToBrowser(message: string): boolean {
|| normalized.includes('window is not defined');
}
function allowLocalhostFallback(): boolean {
try {
return window.localStorage.getItem('clawx:allow-localhost-fallback') === '1';
} catch {
return false;
}
}
export async function hostApiFetch<T>(path: string, init?: RequestInit): Promise<T> {
const startedAt = Date.now();
const method = init?.method || 'GET';
@@ -160,6 +168,17 @@ export async function hostApiFetch<T>(path: string, init?: RequestInit): Promise
if (!shouldFallbackToBrowser(message)) {
throw normalized;
}
if (!allowLocalhostFallback()) {
trackUiEvent('hostapi.fetch_error', {
path,
method,
source: 'ipc-proxy',
durationMs: Date.now() - startedAt,
message: 'localhost fallback blocked by policy',
code: 'CHANNEL_UNAVAILABLE',
});
throw normalized;
}
}
// Browser-only fallback (non-Electron environments).