오후 10시에 벌레를 사냥하는 방법 🌙

작성자

카테고리:

← 피드로
DEV Community · Seif Ahmed · 2026-07-11 개발(SW)

Seif Ahmed

The Story:

Picture this:

  • It is 10 PM.
  • I was eating my dinner while adding one final touch to my social media app, Vlox.
  • It should just say “Processing…” while generating a card.

Simple, right?
See the nightmare. 🔥

The Nightmare Scenario 📉

Suddenly, my “Download Card” button broke.
htmlToImage started spitting out completely empty 0b images.
The hunt was on.

Failed Mission Log 🛰️

  • Attempt 1: Swap to html2canvas 🔄
    • Result: Error stating the element was not found in the cloned iframe.
    • Verdict: The parent container was completely lost.
  • Attempt 2: Use CoolAlertJS Toast 🍞
    • Result: It looked ugly and means loading two different alert libraries for the same job? Not my game.
    • Verdict: Total waste of bundle size.
  • Attempt 3: Append card preview to body + display: none 🙈
    • Result: The canvas process failed entirely.
    • Verdict: Canvas snapshot engines completely ignore hidden elements.

The “Aha!” Moment 💡

Why did the element vanish?
Because the card generator lives entirely inside a Swal popup.
When you click the download/confirm button, Swal instantly destroys that entire popup DOM tree.
You cannot snapshot an element that no longer exists. 👻

The Ultimate Fix 🚀

Inside the new “Processing” popup, I appended the #card-generator-image-preview directly into the new alert container.
The element stays alive in the active DOM.
The snapshot succeeds perfectly.
Clean code. Happy developer. Delicious dinner.

Want to see the exact JavaScript code block that fixed it? Drop a comment below or check Vlox on Github.

원문에서 계속 ↗

코멘트

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다