LS2
LS2

Reputation: 152

Reload a page when JS console error is seen

I see a set of browser error messages on first time loading of a screen. On reloading the page the messages disappear. Is there a way to reload a page when we see JS errors on the console.

Upvotes: 0

Views: 1645

Answers (1)

Rodik
Rodik

Reputation: 4092

You should stop, and think of what you're doing. It's a bad idea. you should be asking how to fix the errors, and not how to silence them.

Also, constantly refreshing the client because of errors is bad UX.

But, hypothetically speaking, this can be done by overriding the console.error method and invoking a browser refresh instead.

like so:

WARNING ---- STUPID CODE AHEAD ---- WARNING

console.error = function(){
   window.location.reload()
}

Upvotes: 2

Related Questions