Fix Anki CORS requests (#666)
This commit is contained in:
parent
fc31e6fab5
commit
f9c76efea0
@ -110,7 +110,7 @@ class AnkiConnect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _invoke(action, params) {
|
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)) {
|
if (isObject(result)) {
|
||||||
const error = result.error;
|
const error = result.error;
|
||||||
if (typeof error !== 'undefined') {
|
if (typeof error !== 'undefined') {
|
||||||
|
@ -16,10 +16,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
async function requestText(url, method, data) {
|
async function requestText(url, method, data, cors=false) {
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
method,
|
method,
|
||||||
mode: 'no-cors',
|
mode: (cors ? 'cors' : 'no-cors'),
|
||||||
cache: 'default',
|
cache: 'default',
|
||||||
credentials: 'omit',
|
credentials: 'omit',
|
||||||
redirect: 'follow',
|
redirect: 'follow',
|
||||||
@ -29,10 +29,10 @@ async function requestText(url, method, data) {
|
|||||||
return await response.text();
|
return await response.text();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function requestJson(url, method, data) {
|
async function requestJson(url, method, data, cors=false) {
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
method,
|
method,
|
||||||
mode: 'no-cors',
|
mode: (cors ? 'cors' : 'no-cors'),
|
||||||
cache: 'default',
|
cache: 'default',
|
||||||
credentials: 'omit',
|
credentials: 'omit',
|
||||||
redirect: 'follow',
|
redirect: 'follow',
|
||||||
|
Loading…
Reference in New Issue
Block a user