From 3ddc107bc21d2c2336e38cb3f1c955efe24bf164 Mon Sep 17 00:00:00 2001 From: Timothee Groleau Date: Sun, 9 Feb 2025 08:48:07 +0800 Subject: [PATCH] fix: safety check and logging for showParts() --- public/ocr/ocr_main.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/public/ocr/ocr_main.js b/public/ocr/ocr_main.js index d1f8598b..4b81ccad 100644 --- a/public/ocr/ocr_main.js +++ b/public/ocr/ocr_main.js @@ -896,13 +896,6 @@ function resetShowPartsTimer() { hide_show_parts_timer = setTimeout(hideParts, 45000); // parts stop showing after 45s of static config } -function loadImage(img, src) { - return new Promise(resolve => { - img.onload = resolve; - img.src = src; - }); -} - function updatePaletteList() { palette_selector.innerHTML = ''; @@ -1548,11 +1541,19 @@ async function showParts(data) { if (config.palette && name.startsWith('color')) continue; const task = config.tasks[name]; - const scale_factor = name.startsWith('color') ? 4 : 2; if (!task) continue; const holder = document.querySelector(`fieldset.${name} div.results`); + + if (!holder) { + console.warn( + `Config controls for [${name}] are not present on page, skipping showing part.` + ); + continue; + } + + const scale_factor = name.startsWith('color') ? 4 : 2; let separator; if (!task.crop_canvas_ctx) {