Skip to content

Commit 783e62a

Browse files
fix: improve error handling in QuizForm; add specific instructions for Ollama setup based on network conditions and browser compatibility
1 parent 1c5177a commit 783e62a

1 file changed

Lines changed: 67 additions & 30 deletions

File tree

‎components/QuizForm.tsx‎

Lines changed: 67 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,15 @@ const QuizForm: FC<Props> = ({
223223
const currentOrigin = window.location.origin;
224224

225225
// Check for various CORS/network error patterns
226+
const isPrivateNetworkAccess =
227+
errorMessage.includes("unknown address space") ||
228+
errorMessage.includes("Access-Control-Allow-Private-Network") ||
229+
errorMessage.includes("private network");
230+
const isSafariLoadFailed = errorMessage.includes("Load failed");
231+
226232
if (
233+
isPrivateNetworkAccess ||
234+
isSafariLoadFailed ||
227235
errorMessage.includes("fetch failed") ||
228236
errorMessage.includes("Failed to fetch") ||
229237
errorMessage.includes("NetworkError") ||
@@ -233,44 +241,73 @@ const QuizForm: FC<Props> = ({
233241
(ollamaError?.name === "TypeError" &&
234242
errorMessage.includes("fetch"))
235243
) {
236-
let setupInstructions =
237-
"Ollama connection failed (likely CORS issue).\n\n";
238-
setupInstructions += "To use Ollama explanations:\n";
244+
let setupInstructions = "Ollama connection failed.\n\n";
245+
setupInstructions += "Browser compatibility:\n";
246+
setupInstructions += "• Firefox – works out of the box\n";
239247
setupInstructions +=
240-
"1. Install Ollama: https://webinstall.dev/ollama/\n";
248+
"• Chrome, Edge – will ask for permission (click Allow)\n";
249+
setupInstructions += "• Opera, Safari – does not work\n\n";
241250

242-
if (isLocalhost) {
251+
if (isSafariLoadFailed) {
243252
setupInstructions +=
244-
"2. Start Ollama: Run `ollama serve` in your terminal\n";
245-
setupInstructions += "3. Refresh this page\n";
246-
} else {
247-
// Detect macOS
248-
const isMac =
249-
navigator.platform.toUpperCase().indexOf("MAC") >= 0;
250-
251-
if (isMac) {
252-
setupInstructions += `2. On macOS, Ollama runs as a service. Set CORS:\n`;
253-
setupInstructions += ` Run: launchctl setenv OLLAMA_ORIGINS "${currentOrigin}"\n`;
254-
setupInstructions += ` Or allow all: launchctl setenv OLLAMA_ORIGINS "*"\n`;
255-
setupInstructions += `3. Quit Ollama app completely (not just terminal)\n`;
256-
setupInstructions += `4. Restart Ollama application\n`;
257-
setupInstructions += `5. Refresh this page\n`;
258-
} else {
259-
setupInstructions += `2. Stop Ollama if running (Ctrl+C)\n`;
260-
setupInstructions += `3. Start with CORS: Run \`OLLAMA_ORIGINS="${currentOrigin}" ollama serve\`\n`;
261-
setupInstructions += `4. Verify origin matches exactly: ${currentOrigin}\n`;
262-
setupInstructions += "5. Refresh this page\n";
263-
}
264-
setupInstructions += "\nTroubleshooting:\n";
265-
setupInstructions += "- Check Ollama logs for 403 errors\n";
253+
"Safari blocks HTTPS sites from accessing HTTP localhost (mixed content).\n\n";
254+
setupInstructions += "Options:\n";
255+
setupInstructions +=
256+
"1. Use Firefox (works out of the box) or Chrome/Edge (click Allow on popup)\n";
257+
setupInstructions +=
258+
"2. Or use this site on localhost: http://localhost:3000 (run npm run dev)\n";
266259
setupInstructions +=
267-
"- Make sure there are no typos in the origin\n";
260+
"3. Or use BYOK/Ditectrev instead of Ollama on this site\n";
261+
} else if (isPrivateNetworkAccess) {
268262
setupInstructions +=
269-
"- On macOS, you must use launchctl, not terminal env vars\n";
263+
"Chrome blocks HTTPS sites from accessing localhost (Private Network Access).\n\n";
264+
setupInstructions += "Setup steps:\n";
270265
setupInstructions +=
271-
"- If 'address already in use': https://github.com/ollama/ollama/issues/707";
266+
"1. Enable CORS in Ollama (see https://objectgraph.com/blog/ollama-cors/ for macOS, Windows, Linux)\n";
267+
setupInstructions +=
268+
' Example: OLLAMA_ORIGINS="*" ollama serve (quit Ollama app first, keep terminal open)\n\n';
269+
setupInstructions +=
270+
"2. Use Firefox (works out of the box) or Chrome/Edge (will ask for permission)\n\n";
271+
setupInstructions +=
272+
'3. If using Chrome/Edge: when popup appears "[site] wants to look for and connect to any device on your local network"\n';
273+
setupInstructions +=
274+
" → Click ALLOW (required for Ollama to work)\n";
275+
} else {
276+
setupInstructions += "To use Ollama explanations:\n";
277+
setupInstructions +=
278+
"1. Install Ollama: https://webinstall.dev/ollama/\n";
279+
setupInstructions +=
280+
" CORS setup (macOS, Windows, Linux): https://objectgraph.com/blog/ollama-cors/\n";
281+
282+
if (isLocalhost) {
283+
setupInstructions +=
284+
"2. Start Ollama: Run `ollama serve` in your terminal\n";
285+
setupInstructions += "3. Refresh this page\n";
286+
} else {
287+
const isMac =
288+
navigator.platform.toUpperCase().indexOf("MAC") >= 0;
289+
290+
if (isMac) {
291+
setupInstructions += `2. Enable CORS: OLLAMA_ORIGINS="*" ollama serve (see https://objectgraph.com/blog/ollama-cors/)\n`;
292+
setupInstructions += ` Quit Ollama app first, keep terminal open\n`;
293+
setupInstructions += `3. Use Firefox (works out of the box) or Chrome/Edge (click Allow on popup)\n`;
294+
} else {
295+
setupInstructions += `2. Enable CORS: https://objectgraph.com/blog/ollama-cors/\n`;
296+
setupInstructions += `3. Use Firefox (works out of the box) or Chrome/Edge (click Allow on popup)\n`;
297+
}
298+
}
272299
}
273300

301+
setupInstructions += "\nTroubleshooting:\n";
302+
setupInstructions +=
303+
"- Full CORS setup (macOS, Windows, Linux): https://objectgraph.com/blog/ollama-cors/\n";
304+
setupInstructions +=
305+
"- Firefox: works out of the box | Chrome/Edge: click Allow on popup | Opera/Safari: not supported\n";
306+
setupInstructions +=
307+
"- Or use this site on localhost (http://localhost:3000) for Ollama\n";
308+
setupInstructions +=
309+
"- If 'address already in use': https://github.com/ollama/ollama/issues/707";
310+
274311
throw new Error(setupInstructions);
275312
}
276313

0 commit comments

Comments
 (0)