-5

I would like to send back the latest errors/log statements from the console as part of a support-request. I do I retrieve the console through javascript/jquery?

2 Answers2

0

You can also override the console.log

(function(){
    if(window.console && console.log){
        var old = console.log;
        console.log = function(){
            doSomthingElse(arguments); 
            old.apply(this, arguments)
        }
    }  
})();
ToujouAya
  • 593
  • 5
  • 24
  • 2
    What about all the other [`console` methods](https://developer.mozilla.org/en/docs/Web/API/console#Methods)? – Phil May 10 '17 at 06:18
  • You need to do it one by one. Here is fully article about override `console` methods http://ourcodeworld.com/articles/read/104/how-to-override-the-console-methods-in-javascript – ToujouAya May 10 '17 at 06:21
0

You can use try... catch

See this example https://jsfiddle.net/j3tfLukr/

var a = {}

try {
   var b = a.b.c
} catch(e) {
  alert(e);
}
Kiran Shinde
  • 5,732
  • 4
  • 24
  • 41
  • 2
    This will cover only that part of code that is written by you – Rajesh May 10 '17 at 06:19
  • To clarify, your code will not cover issues like `$ in undefined` which happens because of delayed loading or accessing `$` before loading jQuery – Rajesh May 10 '17 at 06:30
  • @Rajesh - I would also like to cover issues like $ is undefined as some parts of the application is quite old. Would that be possible? I can see it in the developer console and now I would "just" like to retrieve that :-) – user1697073 May 11 '17 at 06:37
  • @user1697073 for errors, I would suggest using sentry, as mentioned in duplicate I shared under question. If you want to handle manually, I have also shared a JSFiddle link that does something similar, but make sure this script loads before anything else – Rajesh May 11 '17 at 06:40