2

I have been trying to get the Chrome console to clear, however it keeps giving me this error:

Uncaught TypeError: Object #<Console> has no method 'clear'

I honestly have no idea why it keeps giving me this error. console.log(...) works and so do many other console functions, just not clear().

<!DOCTYPE HTML>
<html>
    <head>
         <script>
            console.log("Hello, World.");

            console.clear();
        </script>
    </head>

    <body>

    </body>
</html>

Any Ideas?

EDIT: https://developers.google.com/chrome-developer-tools/docs/console#clearing_the_console_history

states "Invoke console.clear() Console API from JavaScript." So I figured there was some way to use the clear() function from within a javascript script, but I guess I misunderstood.

braX
  • 11,506
  • 5
  • 20
  • 33
Kyle Messner
  • 111
  • 1
  • 1
  • 6

1 Answers1

2

clear() isn't allow to be called from the page's scripts.

In the console, clear() can be executed. It lives at window.console._commandLineAPI.clear and it works in the console because it's ran in this context...

with ((window && window.console && window.console._commandLineAPI) || {}) {
    // console executed code
}
alex
  • 479,566
  • 201
  • 878
  • 984
  • So there is no way to do it automatically? Darn. – Kyle Messner Feb 12 '13 at 08:12
  • @KyleMessner Not without assigning a reference to it from the console. – alex Feb 12 '13 at 08:14
  • @KyleMessner, and that is done by typing this in the console: `window.clear = clear;`. You can then use `clear()`, but you'll have to execute that script in the console manually, each time you load a page. – Cerbrus Feb 12 '13 at 08:17