Sobes.tech
Middle

What happens when an infinite loop (while true) is opened in a browser tab — why does only one tab sometimes hang, and sometimes several?

sobes.tech AI

Answer from AI

When an infinite loop while(true) is running in a single browser tab, that tab starts consuming all available CPU resources because the loop does not terminate and blocks the main JavaScript thread.

Why does sometimes only one tab freeze, and sometimes several:

  • Tab isolation: Modern browsers usually run each tab in a separate process or isolated context. If the loop is stuck in one tab, only that tab freezes, while others continue to work normally.

  • Shared resources: If the browser uses a shared process for multiple tabs (for example, for tabs of the same domain or in older browser versions), a freeze in one tab can affect others because the shared thread is blocked.

  • OS limitations: Under heavy CPU or memory load, the OS may slow down or suspend processes, leading to multiple tabs freezing.

  • Interaction with extensions: Some extensions can affect the operation of multiple tabs if the loop causes errors or locks.

Thus, the behavior depends on the browser architecture, settings, and current system load.

What happens when an infinite loop (while true) is… - sobes.tech