From 1e16cafa74f6206cbdafca770caea998ae0f31b1 Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Tue, 2 Jun 2026 17:49:40 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix:=20Remove=20styles.css=20fro?= =?UTF-8?q?m=20content=5Fscripts=20(was=20breaking=20Claude=20UI),=20impro?= =?UTF-8?q?ve=20background.js=20error=20handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- claude-arabic-voice/background.js | 45 ++++++++++++++++++++++++++----- manifest.json | 3 --- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/claude-arabic-voice/background.js b/claude-arabic-voice/background.js index 38b98a9..7a1e65e 100644 --- a/claude-arabic-voice/background.js +++ b/claude-arabic-voice/background.js @@ -40,6 +40,8 @@ ${text} CORRECTED TEXT:`; + console.log('[ClaudeVoice] Sending to server:', SERVER_URL); + const response = await fetch(SERVER_URL, { method: 'POST', headers: { 'Content-Type': 'application/json' }, @@ -51,19 +53,48 @@ CORRECTED TEXT:`; }); if (!response.ok) { - const errData = await response.json().catch(() => ({})); - const errMsg = errData.error?.message || `HTTP ${response.status}`; + const errText = await response.text().catch(() => ''); + let errMsg; + try { + const errData = JSON.parse(errText); + errMsg = errData.error?.message || `HTTP ${response.status}`; + } catch (e) { + errMsg = `HTTP ${response.status}: ${errText.substring(0, 200)}`; + } throw new Error(`Gemini API error: ${errMsg}`); } - const data = await response.json(); - const resultText = data.candidates?.[0]?.content?.parts?.[0]?.text; + const responseText = await response.text(); + console.log('[ClaudeVoice] Server response received, length:', responseText.length); - if (!resultText) { - throw new Error('Empty response from Gemini API'); + // Try to parse as JSON (Gemini response format from server proxy) + let data; + try { + data = JSON.parse(responseText); + } catch (e) { + // If not JSON, use the raw text + return { text: responseText.trim() }; } - return { text: resultText.trim() }; + // Check if it's a Gemini API response format + if (data.candidates && data.candidates[0]) { + const resultText = data.candidates[0].content?.parts?.[0]?.text; + if (resultText) { + return { text: resultText.trim() }; + } + } + + // Check if it's our server's error format + if (data.error) { + throw new Error(`Server error: ${data.error}${data.details ? ' - ' + JSON.stringify(data.details) : ''}`); + } + + // If we got here but have some text, return it + if (typeof data === 'string') { + return { text: data.trim() }; + } + + throw new Error('Empty response from Gemini API'); } // ─── Installation Handler ──────────────────────────────────────────────────── diff --git a/manifest.json b/manifest.json index 6eab61d..8923df2 100644 --- a/manifest.json +++ b/manifest.json @@ -50,9 +50,6 @@ "js": [ "claude-arabic-voice/content.js" ], - "css": [ - "claude-arabic-voice/styles.css" - ], "run_at": "document_idle" } ],