Search code examples
multithreadinghtmlweb-worker

Why are web workers not allowed to modify the dom


I know web workers work as a separate thread than the UI thread but i dont understand why they are not allowed to modify the DOM. I mean that you can allow inter thread communication and keep the DOM data in a shared space and have the web workers thread modify the DOM. Why is this not allowed in browsers?


Solution

  • Because the DOM is not threadsafe, and JavaScript does not expose a thread API.


    See also: