Do all tabs in a browser window share a single JavaScript thread?

There is no way to answer that in a generic way because this is browser implementation specific.

Pretty much every older browser always used a single thread for every tabs, but more modern browsers / versions might have changed that (for example, chrome has a thread per tab – actually, it even has a whole process per tab).
EDIT: correction from the comment

Actually chrome uses Process-per-site-instance. That means a single
site opened in multiple tabs will still get rendered by the same
process

If you are asking it for performance reasons (kind of like asking “it is ok to block everything in my website using an eternal infinite loop, or will that spread to other tabs”), it is safer to assume that the thread is shared by everyone. If it is in the current browser then you planned for it, and if it isn’t then you get better performance than planned for, hardly a problem.

In order to get some code running in its own thread, have a loop at Web Workers, but they are still far from being fully implemented in every “modern” browsers.

Leave a Comment

tech