Skip to content

Chapter 29 of 33

Web APIs

Use workers, observers, messaging, sockets, media, and permission-gated capabilities.

44 minutes 10 quick checksBy Subha Prasad
Lesson 29 of 33Course navigation

Lesson content

Read, practise, then check your understanding

Web APIs extend JavaScript with browser capabilities. Workers run in separate realms without direct DOM access and communicate using structured-clone messages and transferable objects.

Observe without polling

const observer = new IntersectionObserver(entries => {
  for (const entry of entries) {
    if (entry.isIntersecting) loadPreview(entry.target);
  }
});
observer.observe(document.querySelector("[data-preview]"));

MutationObserver reports DOM changes; ResizeObserver reports element size; WebSocket provides full-duplex messages; BroadcastChannel communicates same-origin contexts. Geolocation, notifications, media, clipboard, and other powerful APIs require secure contexts and permissions. Feature-detect, handle denial, clean up observers/connections, and bound incoming data.

Knowledge check

Answer every question correctly to complete this chapter.

Which statement best describes Web Worker?
Which JavaScript term matches this description: A background JavaScript realm communicating through messages.
Which statement best describes IntersectionObserver?
Which JavaScript term matches this description: An API asynchronously reporting target visibility intersections.
Which statement best describes MutationObserver?
Which JavaScript term matches this description: An API reporting DOM changes in queued records.
Which statement best describes Geolocation?
Which JavaScript term matches this description: A permission-gated API requesting device position.
Which statement best describes WebSocket?
Which JavaScript term matches this description: A persistent full-duplex message channel over one connection.

0 of 10 checks passed

Your progress is saved on this device.