I'm trying to make my app cross-browser by providing two styles, one for browsers that support CSS 3d animation, and one for the browsers that don't, using this code to feature-detect:
// Function from: https://stackoverflow.com/a/36191841/7982963
const isValueSupported = (prop, value) => {
const el = document.createElement('div');
el.style[prop] = value;
return el.style[prop] === value;
}
// [unction from: http://lea.verou.me/2009/02/check-if-a-css-property-is-supported/
const isPropertySupported = property => property in document.body.style;
// Detection style inspired by Modernizr library
if (isValueSupported('perspective', '400px') && isValueSupported('transform-style', 'preserve-3d') && isValueSupported('backface-visibility', 'hidden') && isValueSupported('transform', 'rotateY(-180deg)') && isPropertySupported('perspective') && isPropertySupported('transform-style') && isPropertySupported('backface-visibility') && isPropertySupported('transform') && (!navigator.userAgent.includes('Firefox'))) {
document.documentElement.classList.add('csstransforms3d');
} else {
document.documentElement.classList.add('no-csstransforms3d');
}
The problem is that, although some browsers, like Firefox, pass the test, they have some known bugs like Mozilla's backface-visibility bug, so I had to browser-sniff :(.
I quickly found useful results for Firefox: if (navigator.userAgent.includes('Firefox'))
, but for another browser it happens that I have on my computer called "Baidu browser", I couldn't find any results.
So how to detect these kinds of browsers?