What is wrong with this code #159612
Replies: 6 comments
This comment was marked as spam.
This comment was marked as spam.
-
The error you're seeing, "TypeError: Right-hand side of 'instanceof' is not an object", usually happens because 1. Check the PDF.js Version:You might be using an incompatible version of <script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.10.377/pdf.min.js"></script>
<script>
pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.10.377/pdf.worker.min.js';
</script> |
Beta Was this translation helpful? Give feedback.
This comment was marked as spam.
This comment was marked as spam.
-
The error: TypeError: Right-hand side of 'instanceof' is not an object However, in this version of PDF.js from the CDN, the global object isn't automatically exposed as pdfjsLib. So, pdfjsLib is undefined, which leads to the error you're seeing when calling getDocument(). ✅ Fix This correctly sets up the pdfjsLib object, allowing getDocument() to work as expected. ✅ Optional Debug Tip console.log(pdfjsLib); |
Beta Was this translation helpful? Give feedback.
-
The error ✅ Fix: js js Let me know if you need a clean version of this code. |
Beta Was this translation helpful? Give feedback.
-
🕒 Discussion Activity Reminder 🕒 This Discussion has been labeled as dormant by an automated system for having no activity in the last 60 days. Please consider one the following actions: 1️⃣ Close as Out of Date: If the topic is no longer relevant, close the Discussion as 2️⃣ Provide More Information: Share additional details or context — or let the community know if you've found a solution on your own. 3️⃣ Mark a Reply as Answer: If your question has been answered by a reply, mark the most helpful reply as the solution. Note: This dormant notification will only apply to Discussions with the Thank you for helping bring this Discussion to a resolution! 💬 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Select Topic Area
Question
Body
What is wrong with this code
I asked ChatGPT to write a code and the code I received is below. I ran this code in vscode and the file path doesn't seem to be a problem, but if you're curious, I can capture it and show you. The biggest problem is that when I run it, I get an error like TypeError:
Right-hand side of 'instanceof' is not an object
at Object.getDocument (pdf.min.js:22:16424)
at reader.onload (test.html:74:36).
If you know, please help me.
<title>PDF 슬라이드 + 제스처 리모컨</title> <script src="https://cdn.jsdelivr.net/npm/reveal.js/dist/reveal.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]"></script> <script src="https://cdn.jsdelivr.net/npm/@teachablemachine/[email protected]/dist/teachablemachine-image.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.4.120/pdf.min.js"></script> <script> pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.4.120/pdf.worker.min.js'; </script> <style> body { margin: 0; background: black; } #upload-box { position: fixed; top: 10px; left: 10px; z-index: 999; background: white; padding: 8px; border-radius: 5px; } #webcam-container { position: fixed; top: 10px; right: 10px; width: 320px; height: 240px; border: 2px solid #ccc; background: black; z-index: 1000; } #prediction { position: fixed; top: 260px; right: 10px; width: 320px; color: white; text-align: center; font-weight: bold; z-index: 1000; } </style>})
`; slides.appendChild(section); } Reveal.sync(); } catch (err) { console.error(err); alert("❌ PDF 로딩 중 오류 발생: " + err.message); } }; reader.readAsArrayBuffer(file); }); </script> <script> const URL = "https://teachablemachine.withgoogle.com/models/************/"; let model, webcam, maxPredictions; let lastGesture = "", lastTime = 0; const cooldown = 2000; async function init() { const modelURL = URL + "model.json"; const metadataURL = URL + "metadata.json"; model = await tmImage.load(modelURL, metadataURL); maxPredictions = model.getTotalClasses(); webcam = new tmImage.Webcam(320, 240, true); await webcam.setup(); await webcam.play(); document.getElementById("webcam-container").appendChild(webcam.canvas); window.requestAnimationFrame(loop); } async function loop() { webcam.update(); await predict(); window.requestAnimationFrame(loop); } async function predict() { const prediction = await model.predict(webcam.canvas); const best = prediction.reduce((a, b) => a.probability > b.probability ? a : b); document.getElementById("prediction").innerText = `예측 결과: ${best.className} (${(best.probability * 100).toFixed(1)}%)`; const now = Date.now(); if (best.className === "동작없음") { lastGesture = ""; return; } if (best.probability > 0.85 && best.className !== lastGesture && now - lastTime > cooldown) { lastGesture = best.className; lastTime = now; if (best.className === "손바닥") Reveal.next(); else if (best.className === "주먹") Reveal.prev(); else if (best.className === "브이") Reveal.toggleOverview(); } } init(); </script>Beta Was this translation helpful? Give feedback.
All reactions