<!DOCTYPE html>

    <script data-require="stacktrace.js@*" data-semver="0.5.0" src="//cdnjs.cloudflare.com/ajax/libs/stacktrace.js/0.5.0/stacktrace.js"></script>
    <link rel="stylesheet" href="style.css" />
    <script type="text/javascript">
    // This handler is used to log all client-side errors on server. Place this in head so that this runs first and
    // is ready to catch any errors. If placed at bottom, it's possible that this may not run if an error occurs before!!!
    window.onerror = function(message, url, lineNumber, columnNumber, error) {
      try {
        var stacktrace = printStackTrace({
          e: error || message
        var trace = stacktrace.join('\n');

        var clientSideErrorInfo = {
          message: message,
          url: url,
          stacktrace: trace

        var xhr = new XMLHttpRequest();
        xhr.open("POST", '@Url.Action("Log", "Logger")', true);
        xhr.setRequestHeader("Content-Type", "application/json");
      } catch (e) {
        // Don't allow for infinitely recursively unhandled errors
        return true;
    <script src="script.js"></script>

      <a href="#">http://www.siddharthpandey.net</a>
    <h1>How to log client-side errors of plain JavaScript application to the Server?</h1>
    <p>Check the head section of this html file</p>
    <script type="text/javascript">
      throw new Error("Err..rrr..!!!")

/* Styles go here */