javascriptwebrtcmodernizr

Why is Safari passing this Modernizr test I wrote for WebRTC?


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 CanIUse says that 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.

UPDATE: The above observation is incorrect because manually running the code in the console is being done after webrtc-adapter has loaded, and webrtc-adapter overrides this function.

Why is Safari passing the Modernizr test even though it is listed as unsupported?


Solution

  • It turns out that Safari 14.1 does support this feature, and it seems that it is CanIUse/MDN that is wrong.

    It was added to Webkit in September 2020.