🐛 Fix: Add microphone permission to manifest, add direct fetch fallback for Gemini in content.js
This commit is contained in:
@@ -374,22 +374,85 @@
|
||||
isGeminiProcessing = true;
|
||||
|
||||
try {
|
||||
const response = await chrome.runtime.sendMessage({
|
||||
type: 'GEMINI_PROCESS_VOICE',
|
||||
payload: {
|
||||
apiKey: settings.geminiApiKey,
|
||||
model: settings.geminiModel,
|
||||
text: text,
|
||||
language: settings.language
|
||||
}
|
||||
});
|
||||
// Try via background service worker first
|
||||
let processedText = null;
|
||||
try {
|
||||
const response = await chrome.runtime.sendMessage({
|
||||
type: 'GEMINI_PROCESS_VOICE',
|
||||
payload: {
|
||||
apiKey: settings.geminiApiKey,
|
||||
model: settings.geminiModel,
|
||||
text: text,
|
||||
language: settings.language
|
||||
}
|
||||
});
|
||||
|
||||
if (response && response.success) {
|
||||
const processedText = response.data.text;
|
||||
if (response && response.success) {
|
||||
processedText = response.data.text;
|
||||
} else {
|
||||
console.warn('[ClaudeVoice] Background response not successful:', response?.error);
|
||||
}
|
||||
} catch (bgErr) {
|
||||
console.warn('[ClaudeVoice] Background message failed, trying direct fetch:', bgErr);
|
||||
}
|
||||
|
||||
// Fallback: direct fetch to server
|
||||
if (!processedText) {
|
||||
try {
|
||||
const isArabic = /[\u0600-\u06FF]/.test(text);
|
||||
const langName = isArabic ? 'Arabic' : 'the detected language';
|
||||
|
||||
const prompt = `You are a text refinement assistant. Your task is to:
|
||||
|
||||
1. Correct any speech recognition errors in the following text
|
||||
2. Fix punctuation, capitalization, and formatting
|
||||
3. Keep the original meaning and content intact
|
||||
4. Do NOT add any new information or commentary
|
||||
5. Return ONLY the corrected text, nothing else
|
||||
|
||||
The text is in ${langName}. Preserve the original language.
|
||||
|
||||
TEXT TO REFINE:
|
||||
${text}
|
||||
|
||||
CORRECTED TEXT:`;
|
||||
|
||||
const directResponse = await fetch('https://cv.intaleqapp.com/cv/server/generate_cv.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
action: 'generateText',
|
||||
apiKey: settings.geminiApiKey,
|
||||
prompt: prompt
|
||||
})
|
||||
});
|
||||
|
||||
if (directResponse.ok) {
|
||||
const rawText = await directResponse.text();
|
||||
let data;
|
||||
try {
|
||||
data = JSON.parse(rawText);
|
||||
} catch (e) {
|
||||
data = rawText;
|
||||
}
|
||||
|
||||
if (data && data.candidates && data.candidates[0]) {
|
||||
processedText = data.candidates[0].content?.parts?.[0]?.text;
|
||||
} else if (typeof data === 'string') {
|
||||
processedText = data;
|
||||
}
|
||||
} else {
|
||||
console.warn('[ClaudeVoice] Direct fetch failed:', directResponse.status);
|
||||
}
|
||||
} catch (fetchErr) {
|
||||
console.warn('[ClaudeVoice] Direct fetch error:', fetchErr);
|
||||
}
|
||||
}
|
||||
|
||||
if (processedText) {
|
||||
insertTextIntoClaude(processedText);
|
||||
showStatus('done', '✅ تمت المعالجة بواسطة Gemini');
|
||||
} else {
|
||||
// Fallback: insert original text
|
||||
insertTextIntoClaude(text);
|
||||
showStatus('done', '✅ تم الإدراج (بدون معالجة)');
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
"storage",
|
||||
"activeTab",
|
||||
"scripting",
|
||||
"clipboardWrite"
|
||||
"clipboardWrite",
|
||||
"microphone"
|
||||
],
|
||||
"host_permissions": [
|
||||
"https://www.linkedin.com/*",
|
||||
|
||||
Reference in New Issue
Block a user