0

I have the following code, my goal is to write to a pop up the console error message that results from calling the function "func". I am currently running it in chrome and although I get an error in the console I get no pop up. The reason I am doing this is that I will be running my code in another environment where I won't have access to the console so I would like to be able to extract the error messages so I can view them.

function func(){
    return y
}

(function() {
    var exLog = console.log;
    console.log = function(msg) {
        exLog.apply(this, arguments);
        alert(msg); 
    }
})()
func()
TessavWalstijn
  • 1,698
  • 1
  • 19
  • 36
Mathew
  • 1,116
  • 5
  • 27
  • 59
  • 5
    how is this different from your question 20 mins ago? https://stackoverflow.com/questions/48276737/javascript-write-console-log-to-pop-up – cloned Jan 16 '18 at 08:38
  • 5
    Possible duplicate of [javascript write console log to pop up](https://stackoverflow.com/questions/48276737/javascript-write-console-log-to-pop-up) – Aluan Haddad Jan 16 '18 at 08:38
  • Ya, its the same thing, I was asked by @Adelin to make a new question – Mathew Jan 16 '18 at 08:40
  • Here is what he said: "Your other error is an entirely different error. What do you expect to get with func()? You should add another question for it" – Mathew Jan 16 '18 at 08:40
  • Yeah we basically got to console log to pop up, now fred aims to console errors automatically in popup. To me these are entirelly different topics, although @fred could describe them better – Adelin Jan 16 '18 at 08:41
  • feel free to edit the quesiton, not sure how to best put it – Mathew Jan 16 '18 at 08:44
  • 1
    You might like to know of [weinre](https://people.apache.org/~pmuellr/weinre/docs/latest/), a remote debugging library. You run your code on one environment (e.g. an iPhone Safari), and get a full console in another (e.g. your desktop's Chrome). IMO, way more comfortable than relying on `alert`. – Amadan Jan 16 '18 at 08:46

1 Answers1

0

You can use window.onerror to log the errors

window.onerror = function(msg) {
    alert(msg);
}
EKW
  • 2,059
  • 14
  • 24