From c5fbd6e4e0b703055ce105eb1bd508d3225507a8 Mon Sep 17 00:00:00 2001 From: Fanyo Date: Sun, 11 May 2025 03:33:02 +0200 Subject: [PATCH] Explicitly set content type on xhr request As a user I had to introduce a proxy between the plugin and Anki actual program to work around issues with Snap packaging (Having Obsidian installed as a snap package). That proxy used to set default headers on the request and caused it to be processed incorrectly. This line prevented that for the content type header. It's important because when AnkiConnect does not recognize the content type it returns something like "AnkiConnect v.6" which cause the connection to fail. --- src/anki.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/anki.ts b/src/anki.ts index 10a79044..9bbdda78 100644 --- a/src/anki.ts +++ b/src/anki.ts @@ -34,6 +34,7 @@ export function invoke(action: string, params={}) { }); xhr.open('POST', 'http://127.0.0.1:' + ANKI_PORT.toString()); + xhr.setRequestHeader('Content-Type', 'application/json'); xhr.send(JSON.stringify({action, version: 6, params})); }); }