Limitations
Limitations
Section titled “Limitations”Introduction
Section titled “Introduction”Web Workers run in a separate thread with restricted access to browser APIs.
What Workers Cannot Access
Section titled “What Workers Cannot Access”// ❌ Cannot access:// - DOM (document, window)// - Parent object// - Most browser APIs (localStorage, etc.)// - The main thread's variables or functionsWhat Workers Can Access
Section titled “What Workers Can Access”// ✅ Can access:// - navigator (limited info)// - setTimeout, setInterval// - XMLHttpRequest, fetch// - WebSockets// - IndexedDB// - importScripts() for loading external librariesLoading Libraries
Section titled “Loading Libraries”// importScripts() loads external scripts synchronouslyimportScripts('lodash.js');importScripts('math.js', 'validator.js'); // Multiple files
// Now you can use the loaded librariesconst result = _.chunk(array, 2);Summary
Section titled “Summary”- No DOM access (document, window, parent)
- Can use fetch, WebSockets, IndexedDB
- Load libraries with
importScripts() - Workers are isolated from the main thread’s scope