I am updating the theming system for a website, and I am trying to handle when a <link rel="stylesheet"> element fails to load a theme so that I can have it fallback to a default theme (as well as to identify outdated theme selections, etc.).
In Firefox, I can use the "onerror" event through jQuery before setting the href attribute, e.g. $("#myLinkElement").one("error", handleThemeLoadError).attr("href", themeUrl).
If themeUrl refers to a CSS file that does not exist (resulting in a 404), the handleThemeLoadError is called.
In Chrome, however, the onerror event is never fired. I see the 404 error in the console and network tabs, and Chrome even shows me the line of code where the attribute is set that caused the 404 error, but it will not fire an error event. I have even tried $("#myLinkElement").get(0).onerror = function() { ... }, and I've also tried setting the href attribute to both null and undefined before setting it to the actual URL.
Is there some other way to catch stylesheet load errors in Chrome, or am I completely out of luck?