Optimize gateway comms reload behavior and strengthen regression coverage (#496)
This commit is contained in:
committed by
GitHub
Unverified
parent
08960d700f
commit
1dbe4a8466
@@ -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).
|
||||
|
||||
Reference in New Issue
Block a user