Javscript client side error logging

<script type="text/javascript" src="/static/js/stacktrace.js">
</script>
<script type="text/javascript">

window.onerror = function () {
    var stackTrace, argData, docData, request;
    var _doc = {};

    _doc.URL = document.URL;
    docData = encodeURIComponent(
        JSON.stringify(_doc));
    argData = encodeURIComponent(
        JSON.stringify(arguments));
    stackTrace = JSON.stringify(printStackTrace());

    console.log(arguments);

    request = new XMLHttpRequest();
    request.open(
        'POST', 
        "https://www.yoursite.com/error-logging-url"
    );
    request.setRequestHeader(
        "Content-type",
        "application/x-www-form-urlencoded"
    );
    request.onload = function (e) {};
    request.send(
        "docData=" + docData + "&" + "argData="
       + argData + "&" + "stackTrace=" + stackTrace);

    return false;
}
</script>