1

How could one check if the user enters something in the console? I want a function to run whenever a user enters something in the console, say

function whenUserTypesInConsole() {
    alert('you entered something in the console');
}

and if that can be done, is there a way to check what the user entered

function whenUserTypesInConsole(entry) {
    alert('you entered ' + entry + ' in the console');
}

I would like to avoid using jQuery or any library if possible.

Thanks

jkrei0
  • 188
  • 1
  • 9
  • 1
    Pretty sure it's not possible, at least not without the user installing an extension on their browser beforehand - you're trying to fiddle with *browser internals*, after all, rather than page JS. – CertainPerformance Feb 22 '19 at 22:41
  • Correct, this shouldn’t be possible. (If you ever find a way, please make sure to report it as a bug.) – Ry- Feb 22 '19 at 22:48
  • One way to do this, write a wrapper function which will internally call console.log. In your application, use this wrapper function and not console.log directly. You can then know when console.log is called and call alert in that wrapper function. One advantage of this approach is, if you want to disable using console.log in your app, you just need to comment the func call of console.log in the wrapper. – Sagar Agrawal Feb 23 '19 at 07:41

1 Answers1

0

well here is article on this, will help you for sure, but if you can explain where and why you want to use this. It will be more easier to help you

https://blog.guya.net/chrome/dev_tools/

Yogi
  • 1
  • 1