Handling Resource Events

Resource event types
Category Event types
Loading load, error, abort
Media play, pause, timeupdate, ended ...
Storage storage (fires in other same-origin tabs)
One capturing listener replaces every broken imageJavaScript
addEventListener("error", (e) => {
  const img = e.target;
  if (!(img instanceof HTMLImageElement) || img.dataset.fallback) return;
  img.dataset.fallback = "1";            // avoid a loop if the placeholder fails too
  img.src = "/img/placeholder.svg";
}, { capture: true });

Element load and error events do not bubble, so a window listener sees them only while capturing. Images already in the markup may have loaded before your script ran; check img.complete.