Web Workers execute JavaScript in background threads. They do not have access to the DOM and communicate with the main thread via message passing.
js
const worker = new Worker("worker.js");
worker.postMessage({ data });
worker.onmessage = (e) => console.log(e.data);