Created
June 6, 2023 19:44
-
-
Save varenc/c9f6b902da13195b181d823163faa332 to your computer and use it in GitHub Desktop.
Get original native Chrome console.log function, even if its been overwritten by a page's JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sometimes a page tries to thwart extension developers/hackers by overriding the native console.{log,debug,trace,etc} functions. | |
// Or Sentry wraps them with additional logging and you want to prevent your messages showing up in Sentry logs. | |
// To avoid this, we just create a blank iframe and copy the real native console object from there. | |
const iframe = document.createElement('iframe'); | |
iframe.style.display = 'none'; | |
document.body.appendChild(iframe); | |
const nativeConsole = iframe.contentWindow.console; | |
// now to use the real native console.log function, just call: | |
nativeConsole.log("Using the real console.log!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment