You can (and should) use Web Workers[1], those run off the UI thread, but also don't have access to the DOM.
[1] https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers...