Back to topics

Browser console.log Not Working, No Output

console.log is invalid, no corresponding output in the console.

Investigation Process

  1. The first reaction was that browser extensions might be the issue, so I disabled all extensions.

  2. Then I checked whether there was a problem with webpack configuration, such as incorrectly minifying code in development environment causing console.log to be removed.

  3. The first two steps didn't find the problem, and only this project had the output issue. After being confused for a while, I decided to check if console.log had been hijacked and overwritten.

  4. Directly typed in the console:

console.log
// output: function(){}

Case solved, the console object was hijacked and overwritten. The rest was to find out where it was overwritten.

Conclusion

It turned out that a portion of the code in the HTML template (scripts directly written into the HTML) was pasted after being compressed and obfuscated using a third-party tool.

The obfuscated code overwrote the methods in console, presumably to prevent users from debugging maliciously.