From d81bb3fbf3e1a764434c23d665891fb03385a2f1 Mon Sep 17 00:00:00 2001 From: Marat Fayzullin Date: Wed, 22 Feb 2023 16:48:24 -0500 Subject: [PATCH] Now generating canvas image blob asynchonrously. --- htdocs/openwebrx.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/htdocs/openwebrx.js b/htdocs/openwebrx.js index d9122836..15976d36 100644 --- a/htdocs/openwebrx.js +++ b/htdocs/openwebrx.js @@ -98,19 +98,22 @@ function saveCanvas(canvas) { var c = document.getElementById(canvas); if (c == null) return; - // Create and click a link to the canvas data URL - var a = document.createElement('a'); - a.href = c.toDataURL('image/png'); - a.style = 'display: none'; - a.download = canvas + ".png"; - document.body.appendChild(a); - a.click(); + // Convert canvas to a data blob + c.toBlob(function(blob) { + // Create and click a link to the canvas data URL + var a = document.createElement('a'); + a.href = window.URL.createObjectURL(blob); + a.style = 'display: none'; + a.download = canvas + ".png"; + document.body.appendChild(a); + a.click(); - // Get rid of the canvas data URL - setTimeout(function() { - document.body.removeChild(a); - window.URL.revokeObjectURL(a.href); - }, 0); + // Get rid of the canvas data URL + setTimeout(function() { + document.body.removeChild(a); + window.URL.revokeObjectURL(a.href); + }, 0); + }, 'image/png'); } function zoomInOneStep() {