JavaScript infinite loop

I spent hours trying to narrow down a bug in a template I was making that caused the reviewer to go completely blank. You can’t even study other decks.

It turns out it was an infinite loop (yeah, amateur programmer here lol[1])!

To replicate, add the following to a card template:

<script>
while (true) {}
</script>

A simple infinite loop shouldn’t completely brick Anki!


  1. though in my defense, the bug was caused by modifying the variable used to limit a for loop, inside that loop, so it’s a bit more subtle ↩︎

1 Like

See: Styling & HTML - Anki Manual .

Because Javascript is an advanced feature and so many things can go wrong, Javascript functionality is provided without any support or warranty .

2 Likes

JavaScript has a terrible reputation for making it easy to write errors, so I prefer to avoid it entirely in my card templates, although it’s not always possible. That said, you can write an infinite loop in virtually any language.

I expected Anki to at least destroy the “webview” or whatever is running in the study screen when leaving.

2 Likes

If Anki doesn’t kill the webview when you close the app, that sounds like a bug.

I meant when leaving the study screen and going back to decks screen.

1 Like