I have a script that I can't change that makes a lot of console.log
calls. I want to add another layer and respond if the calls contain certain strings. This works in Firefox, but throws an "Illegal invocation
" error in Chrome on the 4th line:
var oldConsole = {}; oldConsole.log = console.log; console.log = function (arg) { oldConsole.log('MY CONSOLE!!'); oldConsole.log(arg); }
Any ideas how to get around that? I also tried cloning the console...
Console Logs in Chrome: In Google Chrome, the Console Logs are available as a part of Chrome Dev Tools. To open the dedicated Console panel, either: Press Ctrl + Shift + J (Windows / Linux) or Cmd + Opt + J (Mac).
Steps to Open the Console Log in Google Chrome With the Chrome browser open, right-click anywhere in the browser window and select Inspect from the pop-up menu. By default, the Inspect will open the "Elements" tab in the Developer Tools. Click on the "Console" tab which is to the right of "Elements".
console. log specifically is a method for developers to write code to inconspicuously inform the developers what the code is doing. It can be used to alert you that there's an issue, but shouldn't take the place of an interactive debugger when it comes time to debug the code.
press the F12 key on your keyboard.
You need to call console.log
in the context of console
for chrome:
(function () { var log = console.log; console.log = function () { log.call(this, 'My Console!!!'); log.apply(this, Array.prototype.slice.call(arguments)); }; }());
Modern language features can significantly simplify this snippet:
{ const log = console.log.bind(console) console.log = (...args) => { log('My Console!!!') log(...args) } }
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