Example #1
0
        public static string GenerateFriendlyErrorMessage(JavaScriptExecutionHandler javaScriptExecutionHandler, DotNetBrowser.Events.ConsoleEventArgs e)
        {
            // Display the error description:
            string friendlyErrorMessage = "---- JAVASCRIPT ERROR ----"
                                          + Environment.NewLine + Environment.NewLine + "DESCRIPTION: " + (e.Message ?? "n/a");

            // Display the source file and the line where the error occurred:
            if (!string.IsNullOrEmpty(e.Source) && !e.Source.Contains(SimulatorRootFileNameWithoutExtension))
            {
                friendlyErrorMessage += Environment.NewLine + Environment.NewLine + "SOURCE: " + e.Source
                                        + Environment.NewLine + Environment.NewLine + "LINE: " + e.LineNumber.ToString();
            }

            /*
             * // Attempt to display the code that has the issue, if any:
             * if (!string.IsNullOrEmpty(e.Source) && e.Source.Contains(SimulatorRootFileNameWithoutExtension))
             * {
             *  string lastExecutedJavaScriptCode = javaScriptExecutionHandler.GetLastExecutedJavaScriptCode();
             *  if (!string.IsNullOrWhiteSpace(lastExecutedJavaScriptCode))
             *  {
             *      string[] lines = lastExecutedJavaScriptCode.Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
             *      int lineNumber = e.LineNumber;
             *      if (lineNumber > 0 && lineNumber <= lines.Length)
             *      {
             *          lastExecutedJavaScriptCode = lines[lineNumber - 1];
             *      }
             *      friendlyErrorMessage += Environment.NewLine + Environment.NewLine + "LAST EXECUTED CODE:"
             + Environment.NewLine + lastExecutedJavaScriptCode;
             +  }
             + }
             */

            return(friendlyErrorMessage);
        }
Example #2
0
 public JavaScriptErrorsReportingHandler(JavaScriptExecutionHandler javaScriptExecutionHandler, Dispatcher dispatcher)
 {
     _javaScriptExecutionHandler = javaScriptExecutionHandler;
     _dispatcher = dispatcher;
 }