Questions
8 of 20
1What is a Web Worker and why do we need it? What problem does it solve in the browser?
2What are the three types of Web Workers? How do they differ from each other?
3How do you create a Web Worker and communicate with it?
4What is the postMessage / onmessage pattern? Is communication synchronous or asynchronous?
5What APIs and features are not available inside a Web Worker? (e.g., DOM, window, document)
6What is the Structured Clone Algorithm? How is it different from JSON serialization? What types can and cannot be cloned?
7What are Transferable Objects? How does transferring an ArrayBuffer differ from cloning it, and why does it matter for performance?
8How do you handle errors inside a Web Worker? What events are available and what information do they expose?
9What is a Shared Worker? How can multiple browser tabs communicate through one? What are its limitations?
10How do you terminate a Web Worker? What's the difference between worker.terminate() and self.close()?
11How would you architect a thread pool using Web Workers to process a large task queue efficiently?
12What is SharedArrayBuffer and Atomics? How do they enable true shared memory between the main thread and workers? What security headers are required to use them?
13What are the performance trade-offs of using Web Workers? When can they actually hurt performance (e.g., small tasks, frequent postMessage calls)?
14How would you use Web Workers with WebAssembly (WASM) for CPU-intensive tasks? What makes this combination powerful?
15How do Module Workers work (type: 'module')? What advantages do they offer over classic workers?
16In a React or Vue app, how would you integrate a Web Worker cleanly without breaking the component lifecycle? Have you used libraries like comlink — how does it simplify the worker communication model?
17What is the lifecycle of a Service Worker (install → activate → fetch)? How do you handle cache versioning and old worker cleanup?
18What is the difference between cache.put(), cache.add(), and cache.addAll()? How do you implement a cache-first vs network-first strategy?
19How do you communicate between a Service Worker and the main thread? What is the role of BroadcastChannel vs postMessage here?
20Can Web Workers access localStorage?
08 / 20

How do you handle errors inside a Web Worker? What events are available and what information do they expose?

Difficulty: 5/10
Web Workers, Error handling, ErrorEvent

Use onerror event (or addEventListener('error')) in the worker and main thread. Error object contains message, filename, lineno, colno.

Error handling

Scenario Questions

0-2 years experience

  1. 1You need to fetch data in a Web Worker and want to log any errors that occur. How would you set up error handling inside the worker and in the main thread?
  2. 2If a worker throws a ReferenceError, what event fires on the main thread and what properties can you inspect to understand the failure?

2-5 years experience

  1. 1During a feature rollout, a worker sometimes crashes with an uncaught exception. Walk me through how you'd debug it using the events available.
  2. 2You notice that errors from a worker aren't reaching your logging service. What could be going wrong with your error handling setup, and how would you fix it?
  3. 3Explain the trade‑offs between handling errors inside the worker with try/catch versus relying on the worker's onerror event.

5-8 years experience

  1. 1Design a robust error‑handling layer for a system that spawns many workers to process user uploads. How would you capture, aggregate, and react to errors across workers without leaking resources?
  2. 2When a worker encounters an error, you need to decide whether to restart it or fallback to a main‑thread implementation. What factors influence that decision, and how would you implement the logic?
  3. 3Discuss how you would instrument error events to work with a centralized monitoring system while preserving performance.

8+ years experience

  1. 1Our platform plans to migrate several CPU‑intensive services to Web Workers across multiple teams. How would you define a cross‑team strategy for error handling, reporting, and versioning of worker scripts?
  2. 2Consider a legacy codebase where workers were created without any error handling. Propose a phased approach to retrofit error handling and ensure backward compatibility.
  3. 3What architectural patterns could you use to isolate worker failures so they don't cascade into the main application, especially under high load?

Follow-up Questions

  • What properties does the ErrorEvent expose that help you pinpoint the failure?
  • How would you differentiate between a runtime exception and a syntax error in a worker?
  • Can you recover from a worker error without terminating the whole page, and if so, how?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.