From f113b54801e4fd51c9ca34da1fccdae21c3b8870 Mon Sep 17 00:00:00 2001 From: Christian Denker Date: Tue, 1 Oct 2024 14:23:34 +0200 Subject: [PATCH] add check if object is defined --- index.html | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index 8c612fd..039dd84 100644 --- a/index.html +++ b/index.html @@ -227,14 +227,22 @@ document.addEventListener('touchend', endDrag); function startDrag(e) { - pollyMessageListener.postMessage('startDrag') + if (pollyMessageListener && typeof pollyMessageListener.postMessage === 'function') { + pollyMessageListener.postMessage('startDrag'); + } else { + console.warn('pollyMessageListener is not defined or does not support postMessage'); + } isDragging = true; e.preventDefault(); document.getElementById('arrows').style.visibility = 'hidden'; } function onDrag(e) { - pollyMessageListener.postMessage('onDrag') + if (pollyMessageListener && typeof pollyMessageListener.postMessage === 'function') { + pollyMessageListener.postMessage('onDrag'); + } else { + console.warn('pollyMessageListener is not defined or does not support postMessage'); + } if (!isDragging) return; let clientX = e.clientX || e.touches[0].clientX; @@ -253,8 +261,11 @@ } function endDrag() { - pollyMessageListener.postMessage('endDrag') - + if (pollyMessageListener && typeof pollyMessageListener.postMessage === 'function') { + pollyMessageListener.postMessage('endDrag'); + } else { + console.warn('pollyMessageListener is not defined or does not support postMessage'); + } isDragging = false; if (userResult === null) return; if (hasSubmitted) {