I wanted a Modernizr test to check for setLocalDescription with description optional. Here is what I came up with:
window.Modernizr.addTest('paramlessrtclocaldescription', function () {
try {
return window.RTCPeerConnection.prototype.setLocalDescription.length === 0;
} catch (err) {
// This can only happen if the browser doesn't support RTCPeerConnection, and
// we have a separate test for that, but we don't want this test to crash
// the script.
return false;
}
});
When I run this test in Firefox 73 (on Windows, from PortableApps.com), it properly returns false.
However, when I run it in Safari 14.1, the test returns true, even though Safari does not support this function.
Furthermore, when I open the JS Console and type window.RTCPeerConnection.prototype.setLocalDescription.length, it returns 3 and window.RTCPeerConnection.prototype.setLocalDescription.length === 0 returns false.
Why is Safari passing the Modernizr test when manually running it in the console shows that it would have failed? How can I make it fail properly?
Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW
Comments
Post a Comment