devtools logo
by Ryan Macalandag
Back to cheatsheets
Cheatsheetsbrowserjavascriptapi

Browser API Cheatsheet

Web platform APIs from Fetch to Intersection Observer.

Fetch & requests

The Fetch API returns a Promise that resolves once headers arrive — you still need a second step to read the body.

fetch(url)

sends the request

Response

headers + status resolve

response.json()

reads and parses the body

Basic fetch with error handling
const response = await fetch('/api/users')
if (!response.ok) throw new Error(`Request failed: ${response.status}`)
const users = await response.json()

Client-side storage

APIPersistsBest for
localStorageUntil clearedSmall key-value preferences (strings only).
sessionStorageUntil tab closesTransient state scoped to one tab.
CookiesUntil expiryData the server needs to read too, e.g. session tokens.
IndexedDBUntil clearedLarger structured data, offline-first apps.
Cache APIUntil clearedCaching network responses, typically via a Service Worker.

Observers

APIWatches
IntersectionObserverWhen an element enters/exits the viewport — infinite scroll, lazy loading, fade-ins.
ResizeObserverAn element's size changing — responsive components without a window resize listener.
MutationObserverChanges to the DOM tree itself — attributes, children, text.
PerformanceObserverPerformance entries like Core Web Vitals (LCP, CLS, INP).

Workers

APIRunsGood for
Web WorkerBackground thread, tied to one tabCPU-heavy work off the main thread (parsing, image processing).
Service WorkerBackground, shared across tabs/originOffline caching, push notifications, PWA install.

Realtime & messaging

APIDirectionGood for
WebSocketBidirectionalChat, live cursors, collaborative editing.
EventSource (SSE)Server → client onlyStreaming updates, AI token streaming, live logs.
BroadcastChannelTab ↔ tab, same originSyncing state across open tabs (e.g. logout everywhere).

Device & media

APIDoes
navigator.clipboardRead/write the system clipboard (requires a user gesture).
navigator.geolocationRequest the user's current position — always permission-gated.
NotificationShow a native OS notification, after requesting permission.
MediaDevices.getUserMediaAccess the camera/microphone stream.

History & URL

APIDoes
history.pushState()Add a new entry to the browser history without a full navigation.
history.replaceState()Replace the current entry — no back-button entry created.
new URL(str)Parse a URL into its parts (origin, pathname, searchParams).
URLSearchParamsRead and build query strings without manual string concatenation.

Spot an error or have a suggestion? Open an issue on GitHub.