You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When connection fails due to CORS, automatically request permission
from Anki which triggers a popup for the user to grant access.
This is much more user-friendly than requiring manual config edits.
Based on implementation from Mangatan-WebUI (MPL-2.0)
https://github.com/KolbyML/Mangatan-WebUICloses#151
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@@ -453,14 +480,21 @@ export async function testConnection(testUrl?: string): Promise<ConnectionTestRe
453
480
consterrorMessage=e?.message??String(e);
454
481
455
482
// CORS errors typically show as "Failed to fetch" or similar network errors
456
-
// but we can check if it's a TypeError which often indicates CORS
457
483
if(einstanceofTypeError&&errorMessage.includes('Failed to fetch')){
458
-
// Could be CORS or network - provide guidance for both
484
+
// Try requesting permission from Anki - this triggers a popup in Anki
485
+
constgranted=awaitrequestAnkiPermission(url);
486
+
487
+
if(granted){
488
+
// Permission granted, retry the connection
489
+
returntestConnection(testUrl);
490
+
}
491
+
492
+
// Permission not granted or request failed
459
493
return{
460
494
success: false,
461
495
error: 'cors',
462
496
message:
463
-
'Cannot connect. Either Anki is not running, the URL is wrong, or CORS is not configured. Add this site to webCorsOriginList in AnkiConnect settings.'
497
+
'Connection blocked. If Anki showed a permission popup, click "Yes" and try again. Otherwise, add this site to webCorsOriginList in AnkiConnect settings.'
464
498
};
465
499
}
466
500
@@ -483,7 +517,7 @@ export async function testConnection(testUrl?: string): Promise<ConnectionTestRe
0 commit comments