diff --git a/web_ext/sseq_gui/interface/index.js b/web_ext/sseq_gui/interface/index.js index 4b1cfb96c..819a8f3a8 100644 --- a/web_ext/sseq_gui/interface/index.js +++ b/web_ext/sseq_gui/interface/index.js @@ -278,11 +278,18 @@ messageHandler.Error = m => { document.getElementById('json-upload').addEventListener('change', () => { const file = document.getElementById('json-upload').files[0]; const fileReader = new FileReader(); + fileReader.onload = e => { - // Remove whitespace to shorten URL - const json = JSON.stringify(JSON.parse(e.target.result)); - window.location = `?module_json=${encodeURIComponent(json)}`; + try { + // Remove whitespace to shorten URL + const json = JSON.stringify(JSON.parse(e.target.result)); + window.location = `?module_json=${encodeURIComponent(json)}`; + } catch (error) { + alert('Invalid JSON file: ' + error.message); + console.error('Error parsing JSON:', error); + } }; + fileReader.readAsText(file, 'UTF-8'); });