To centralize our Javascript warnings and errors we use the window.onerror listener.
Unfortunately this does not catch Chrome deprecation warnings which are only shown on the console.
Is there a way to catch those warnings with Javascript?
Example code to trigger a Chrome deprecation warning (Needs a recent version of Chrome):
<!DOCTYPE HTML>
<html>
<head><title>Chrome test</title></head>
<body>
<div class="text">Hallo</div>
<script>
const range = document.createRange()
range.selectNode(document.querySelector('.text'))
window.getSelection().addRange(range)
window.getSelection().addRange(range)
</script>
</body>
</html>
Deprecation warnings, and the like, are added by the browser after your code ran in it, when it detects patterns or behaviors that are about to be changed/deprecated. The idea is that you follow the link provided, and amend your code to fit the future version, as your code would break once that version is out.
As such, you cannot catch those in your code - nor should you want to. You want to see those in testing and fix/future proof your code.
If you don't want to see those warnings in your Developer Tools, go to Settings, under Console, check "User messages only", and you won't see those warnings again
Caveat: these instructions fit Chrome 61. Developer Tools settings keep shifting between versions, so it may look differently disabling Chrome messages in your browser - but it should be similar.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With