From f9c76efea00ff62021119c4d0fcf414e8988be1d Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Fri, 17 Jul 2020 14:27:57 -0400 Subject: Fix Anki CORS requests (#666) --- ext/bg/js/anki.js | 2 +- ext/bg/js/request.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'ext') diff --git a/ext/bg/js/anki.js b/ext/bg/js/anki.js index 55953007..a8872a52 100644 --- a/ext/bg/js/anki.js +++ b/ext/bg/js/anki.js @@ -110,7 +110,7 @@ class AnkiConnect { } async _invoke(action, params) { - const result = await requestJson(this._server, 'POST', {action, params, version: this._localVersion}); + const result = await requestJson(this._server, 'POST', {action, params, version: this._localVersion}, true); if (isObject(result)) { const error = result.error; if (typeof error !== 'undefined') { diff --git a/ext/bg/js/request.js b/ext/bg/js/request.js index d1c6ed4e..4a455850 100644 --- a/ext/bg/js/request.js +++ b/ext/bg/js/request.js @@ -16,10 +16,10 @@ */ -async function requestText(url, method, data) { +async function requestText(url, method, data, cors=false) { const response = await fetch(url, { method, - mode: 'no-cors', + mode: (cors ? 'cors' : 'no-cors'), cache: 'default', credentials: 'omit', redirect: 'follow', @@ -29,10 +29,10 @@ async function requestText(url, method, data) { return await response.text(); } -async function requestJson(url, method, data) { +async function requestJson(url, method, data, cors=false) { const response = await fetch(url, { method, - mode: 'no-cors', + mode: (cors ? 'cors' : 'no-cors'), cache: 'default', credentials: 'omit', redirect: 'follow', -- cgit v1.2.3