Search code examples
javascriptbrowserify

Javascript : Uncaught TypeError: Illegal invocation


Here bundle.js is bundled through browserify which includes a module called webrtcsupport

<script type="text/javascript" src="/assets/js/bundle.js"></script>
<script type="text/javascript">
    var webrtcSupport = require('webrtcsupport');
    console.log(webrtcSupport.getUserMedia);
    webrtcSupport.getUserMedia();
</script>

Output in browser(Chrome browser) console:

function webkitGetUserMedia() { [native code] }
Uncaught TypeError: Illegal invocation

Why cant I invoke the above function in this manner and what is the right way of doing it?


Solution

  • The error "Illegal Invocation" is usually caused when the invocation context is invalid. In case of .getUserMedia() it expects the context to be of navigator.

    Try webrtcSupport.getUserMedia.call(navigator, ...);