Changes
This commit is contained in:
@@ -46,6 +46,20 @@ function clearLogs() {
|
|||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fallback UUID generator for environments where crypto.randomUUID is unavailable
|
||||||
|
function generateUUID(): string {
|
||||||
|
try {
|
||||||
|
return crypto.randomUUID();
|
||||||
|
} catch {
|
||||||
|
// Fallback implementation
|
||||||
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
||||||
|
const r = (Math.random() * 16) | 0;
|
||||||
|
const v = c === 'x' ? r : (r & 0x3) | 0x8;
|
||||||
|
return v.toString(16);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Intercept fetch (dev only)
|
// Intercept fetch (dev only)
|
||||||
const isDev = import.meta.env.DEV;
|
const isDev = import.meta.env.DEV;
|
||||||
const originalFetch = window.fetch;
|
const originalFetch = window.fetch;
|
||||||
@@ -55,6 +69,7 @@ const globalAny = window as unknown as { __gatehouseFetchPatched?: boolean };
|
|||||||
if (isDev && !globalAny.__gatehouseFetchPatched) {
|
if (isDev && !globalAny.__gatehouseFetchPatched) {
|
||||||
globalAny.__gatehouseFetchPatched = true;
|
globalAny.__gatehouseFetchPatched = true;
|
||||||
|
|
||||||
|
try {
|
||||||
window.fetch = async function (input, init) {
|
window.fetch = async function (input, init) {
|
||||||
const url =
|
const url =
|
||||||
typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
||||||
@@ -71,7 +86,7 @@ if (isDev && !globalAny.__gatehouseFetchPatched) {
|
|||||||
return originalFetch.apply(this, [input, init]);
|
return originalFetch.apply(this, [input, init]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const id = crypto.randomUUID();
|
const id = generateUUID();
|
||||||
const method = init?.method || "GET";
|
const method = init?.method || "GET";
|
||||||
let requestBody: unknown;
|
let requestBody: unknown;
|
||||||
|
|
||||||
@@ -148,9 +163,14 @@ if (isDev && !globalAny.__gatehouseFetchPatched) {
|
|||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
} catch (patchError) {
|
||||||
|
// Log any errors during fetch patching with full stack trace
|
||||||
|
console.error("[Gatehouse DevTools] Failed to patch fetch:", patchError);
|
||||||
|
if (patchError instanceof Error) {
|
||||||
|
console.error("[Gatehouse DevTools] Stack trace:", patchError.stack);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// isDev is already declared at module level for the fetch patch
|
|
||||||
export default function ApiDevTools() {
|
export default function ApiDevTools() {
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const [logs, setLogs] = useState<ApiLog[]>([...apiLogs]);
|
const [logs, setLogs] = useState<ApiLog[]>([...apiLogs]);
|
||||||
|
|||||||
Reference in New Issue
Block a user