[Proposal] Error handling for ResizeObserver

The Salesforce Web Standards team have been working on a solution to handle errors for observer.

For some TL;DR:

The error from the callback function cannot be captured from registering the elements through the .observe method. The registration does not imply a call to that function.

const observer = new ResizeObserver(function() {
    throw new Error();
});

try {
    observer.observe(elem1);
} catch (e) {
    // the only error to be captured here is if elem1 don't meet the parameters requirements
    // the Error thrown would leak up to `window.onerror`
}

This proposal adds a .catch method with a callback to remove the bubbling out.

This method captures errors triggered in the callback function. E.g.:

var observer = new ResizeObserver(function(entries) {
    throw new Error('meep');
});
observer.observe(elem1);
observer.observe(elem2);

// The new proposed method
observer.catch(function(err) {
    console.log(err.message); // 'meep'
});

We want to bring this to the proper standards venues with the adequate members and implementers support. Therefore, we’re happy to discuss this proposal in order to advance it.

2 Likes