From 52243557a26320ec21be0cf4cbc6be2d2135ac68 Mon Sep 17 00:00:00 2001 From: Ehab Younes Date: Mon, 8 Dec 2025 16:24:59 +0300 Subject: [PATCH] fix: do not log CSRF error in Electron environments (#21054) Closes #20914 --- site/src/api/api.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/site/src/api/api.ts b/site/src/api/api.ts index 6f6edf44ea..9c8b337939 100644 --- a/site/src/api/api.ts +++ b/site/src/api/api.ts @@ -2783,15 +2783,18 @@ function getConfiguredAxiosInstance(): AxiosInstance { if (process.env.NODE_ENV === "development") { // Development mode uses a hard-coded CSRF token instance.defaults.headers.common["X-CSRF-TOKEN"] = csrfToken; - instance.defaults.headers.common["X-CSRF-TOKEN"] = csrfToken; tokenMetadataElement.setAttribute("content", csrfToken); } else { instance.defaults.headers.common["X-CSRF-TOKEN"] = tokenMetadataElement.getAttribute("content") ?? ""; } } else { - // Do not write error logs if we are in a FE unit test. - if (!process.env.JEST_WORKER_ID && !process.env.VITEST) { + // Do not write error logs if we are in a FE unit test or if there is no document (e.g., Electron) + if ( + typeof document !== "undefined" && + !process.env.JEST_WORKER_ID && + !process.env.VITEST + ) { console.error("CSRF token not found"); } }