From 5652b67a07fa82b8685a2ab87c5ed2643017d4bf Mon Sep 17 00:00:00 2001 From: Vadym Samoilenko Date: Thu, 12 Mar 2026 18:19:46 +0000 Subject: [PATCH] Fix progress bar stuck at 30% during Cloud Run synchronous processing Cloud Run processes PDFs synchronously (2-5 min). The await startCheck() call blocks JS, so progress never advanced past 30%. Add a setInterval timer before the await that advances through realistic stages every 18s, covering the full processing window. Timer is cleared on completion/error. Co-Authored-By: Claude Sonnet 4.6 --- js/upload.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/js/upload.js b/js/upload.js index a364f49..fe1c042 100644 --- a/js/upload.js +++ b/js/upload.js @@ -99,9 +99,32 @@ async function beginCheck() { const quickMode = document.getElementById('quickMode').checked; if (quickMode) addLog('Quick mode enabled — skipping expensive checks', 'info'); + // Animate progress while Cloud Run processes synchronously (can take 2-5 min) + const progressStages = [ + { pct: 35, msg: 'Loading PDF structure...', log: 'Reading PDF metadata and tagging' }, + { pct: 45, msg: 'Checking document structure...', log: 'Validating PDF tags and structure tree' }, + { pct: 55, msg: 'Analyzing images with AI...', log: 'Running AI vision analysis on images' }, + { pct: 65, msg: 'Checking color contrast...', log: 'Calculating WCAG contrast ratios' }, + { pct: 72, msg: 'Analyzing readability...', log: 'Computing Flesch reading scores' }, + { pct: 80, msg: 'Checking headings & links...', log: 'Heading hierarchy, tab order, role mapping' }, + { pct: 88, msg: 'Running PDF/UA validation...', log: 'veraPDF structure validation' }, + { pct: 94, msg: 'Compiling results...', log: 'Generating accessibility report' }, + ]; + let stageIdx = 0; + const progressTimer = setInterval(() => { + if (stageIdx < progressStages.length) { + const s = progressStages[stageIdx++]; + updateProgress(s.pct, s.msg); + addLog(s.log, 'info'); + } + }, 18000); // advance every 18s → covers ~2.5 min of processing + + updateProgress(30, 'Analyzing PDF (this may take a few minutes)...'); + addLog('Sent to Cloud Run for processing...', 'info'); + try { - updateProgress(30, 'Analyzing PDF (this may take a few minutes)...'); const result = await startCheck(currentJobId, quickMode); + clearInterval(progressTimer); if (result.success) { if (result.data && result.data.status === 'completed') { @@ -121,6 +144,7 @@ async function beginCheck() { document.getElementById('progressContainer').style.display = 'none'; } } catch (error) { + clearInterval(progressTimer); addLog('Check error: ' + error.message, 'error'); alert('Check failed: ' + error.message); document.getElementById('progressContainer').style.display = 'none';