7

I came across a website that runs this code:

function check(){console.clear();before = new Date().getTime();…
                 ^^^^^^^^^^^^^^^

on load, discarding valuable console messages. How can I make Firefox ignore console.clear() globally?

I wonder why that even exists in the first place. It should not be possible for a website to delete potentially relevant debugging output.

Philipp Gesang
  • 496
  • 1
  • 6
  • 16

3 Answers3

5

You can solve this in two ways,

First, you can write a firefox extension which executes a javascript on page load and assigns empty function to console.clear. So, it doesn't throw any error if its called.

console.clear = () => {}

References for building extension to run on page load Chrome Extension: Make it run every page load https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Modify_a_web_page

Secondly, you can load the page once and open devtools and goto sources and search for console.clear and add breakpoints every where its called and reload the page. The code execution will stop when the console.clear is called for the first time and again you can goto console and assign console.clear with empty function and override.

Reference for Using BreakPoints in Firefox https://developer.mozilla.org/en-US/docs/Tools/Debugger/How_to/Set_a_breakpoint

Syed
  • 364
  • 1
  • 8
  • upvote for you. Do you know an easy way to search for a string such as `console.clear` across all sources in devtools? – DrLightman Dec 30 '20 at 11:33
3

Since you're asking about Firefox, if you don't want to write your own extension, you can use the one that already exists:

Disallow Console Clear Firefox Addon

0

It is right to hijack the console.clear on page load.


Here just a tip/record.

For some sites, there would be no explicit word console.clear in the sources. (And sadly, currently Firefox's Preserve Log option might still not be as powerful as Chrome's)

But the hijack might still work even!

BTW it might happen that "directly reassigning console.clear in console" not works.

So just try it.

laoyb
  • 99
  • 2
  • 8