Skip to content

Instantly share code, notes, and snippets.

@varenc
Created June 6, 2023 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save varenc/c9f6b902da13195b181d823163faa332 to your computer and use it in GitHub Desktop.
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
// 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