useCapture for window errors

UseCapture allows us to capture error events on window in the capture phase (not bubble phase)

by David Iglesias

HTML

<img id="foo" />

JavaScript

var image = document.querySelector('#foo');

// OK
image.addEventListener('error', function(error) {
  console.log('Captured from image element', error.type);
});

// OK
window.addEventListener('error', function(error) {
  console.log('Captured from window (capture: true)', error.type);
  console.log('src:', error.target.src);
}, {
  capture: true
});

// Wrong
window.addEventListener('error', function(error) {
  console.log('Captured from window', error.type);
});

image.src = "force-a-404-error.jpg";