diff --git a/lib/esbonio/changes/665.fix.md b/lib/esbonio/changes/665.fix.md new file mode 100644 index 000000000..b087c4e39 --- /dev/null +++ b/lib/esbonio/changes/665.fix.md @@ -0,0 +1 @@ +Fix handling of binary websocket messages in documentation previews diff --git a/lib/esbonio/esbonio/sphinx_agent/static/webview.js b/lib/esbonio/esbonio/sphinx_agent/static/webview.js index c380495f3..54e4e4bd5 100644 --- a/lib/esbonio/esbonio/sphinx_agent/static/webview.js +++ b/lib/esbonio/esbonio/sphinx_agent/static/webview.js @@ -221,7 +221,10 @@ const showMarkers = queryParams.has("show-markers") const wsUrl = queryParams.get("ws"); console.debug(`Connecting to '${wsUrl}'...`) +const textDecoder = new TextDecoder() const socket = new WebSocket(wsUrl); +socket.binaryType = 'arraybuffer' + let connected = false function sendMessage(data) { @@ -279,7 +282,16 @@ socket.addEventListener("open", (event) => { // Listen for messages socket.addEventListener("message", (event) => { - handle(JSON.parse(event.data)) + let message + + if (event.data instanceof ArrayBuffer) { + let buf = new Uint8Array(event.data) + message = JSON.parse(textDecoder.decode(buf)) + } else { + message = JSON.parse(event.data) + } + + handle(message) }); function main() {