diff --git a/static/scripts.js b/static/scripts.js index 44c2436..2d78f06 100644 --- a/static/scripts.js +++ b/static/scripts.js @@ -454,7 +454,7 @@ async function verifyProof(url, fingerprint) { output.qr = url; try { - response = await fetch(output.proofUrl); + response = await fetchWithTimeout(output.proofUrl); if (!response.ok) { throw new Error('Response failed: ' + response.status); } @@ -877,6 +877,15 @@ async function generateProfileURL(data) { } } +async function fetchWithTimeout(url, timeout = 3000) { + return Promise.race([ + fetch(url), + new Promise((_, reject) => + setTimeout(() => reject(new Error('timeout')), timeout) + ) + ]); +} + // General purpose let elFormVerify = document.body.querySelector("#form-verify"), elFormEncrypt = document.body.querySelector("#form-encrypt"),