Infinite loop freezes the tab with no error
Locate the failed assumption, reproduce it, then repair the cause.
What actually caused it
The loop keeps running and never reaches an exit. The main thread cannot process normal input or rendering while that work continues, so the page can appear frozen without producing a JavaScript exception.
Trace the condition and the update together. A missing increment, an update in the wrong direction, a continue that skips the update, or a loop that keeps extending the collection it is visiting can prevent termination.
A very large finite loop can produce a similar symptom. Measure and inspect the work rather than assuming every freeze is literally infinite. Setting a timeout elsewhere does not interrupt a currently running loop.
Minimal reproduction
A condition that never changes
let index = 0;
while (index < 3) {
console.log(index);
}This reproduction intentionally never finishes. Read it here; do not paste it into a valuable live tab.
The fix
Write down the starting state, one 's change, and the condition that eventually stops repetition. Make every repeating path progress toward that condition, or exit explicitly with a justified break.
During diagnosis, a temporary counter can throw before the browser becomes unusable. Remove that arbitrary debugging limit once you have established the correct rule, or replace it with a documented domain limit. For genuinely large work, reduce the work or split it into scheduled chunks or a worker as appropriate.
Advance toward the stopping condition
let index = 0;
while (index < 3) {
console.log(index);
index += 1;
}Temporary guard while investigating
let index = 0;
let iterations = 0;
while (index < 3) {
if (++iterations > 10) throw new Error("Loop exceeded the diagnostic limit");
console.log(index);
index += 1;
}The counter is a diagnostic aid. The index update is what makes this particular loop correct.