RESOLVED FIXED 72818
Web Inspector: console.clear() implementation
https://bugs.webkit.org/show_bug.cgi?id=72818
Summary Web Inspector: console.clear() implementation
Milos Gavrilovic
Reported 2011-11-19 18:31:22 PST
In Firefox you can do console.clear() to clear entire content that you added with console.log(), but in Web Inspector that is not working. When you try to use it in Web Inspector you get this error: Uncaught TypeError: Object #<Console> has no method 'clear' (anonymous function) What i would love to see is that this little method gets implemented into Web Inspector, I'm pretty sure that i am not the only one in need for a better solution to clear console(across multiple browsers), this solution(and other like that) is just not that great: http://t.co/b87PGGfp
Attachments
Milos Gavrilovic
Comment 1 2011-11-19 18:47:23 PST
Sorry, i meant to say that you can do console.clear() in Firebug for Firefox... :)
Pavel Feldman
Comment 2 2011-11-19 23:15:42 PST
(In reply to comment #0) > In Firefox you can do console.clear() to clear entire content that you added with console.log(), but in Web Inspector that is not working. > > When you try to use it in Web Inspector you get this error: > > Uncaught TypeError: Object #<Console> has no method 'clear' > (anonymous function) > > What i would love to see is that this little method gets implemented into Web Inspector, I'm pretty sure that i am not the only one in need for a better solution to clear console(across multiple browsers), this solution(and other like that) is just not that great: http://t.co/b87PGGfp Although console.clear is a part of http://getfirebug.com/wiki/index.php/Console_API, I am not convinced that it is a goog idea: imagine an iframe that is clearing the console and preventing you from debugging of the main page. You could 1) issue "clear()" in the console to clear it see the command line API: http://getfirebug.com/wiki/index.php/Command_Line_API. Or use keyboard shortcut to clear console. 2) use keyboard shortcut (hit "?" to get the shortcut for your platform). Feel free to reopen this change (or post a comment asking to reopen) if you have a scenario that requires you to clear console programmatically from the web facing API.
Milos Gavrilovic
Comment 3 2011-11-20 03:00:26 PST
Hey Pavel, i really think there is a valid case here, for example few days ago i was doing some credit card validation where i had about 3-4 client requests on how to handle different scenarios: 1. credit card type 2. credit card length 3. credit card prefix 4. MOD10 check of credit card number: http://www.beachnet.com/~hstiles/cardtype.html This is fired each time when validation for that credit card field is called(onkeyup or on blur): console.clear() for(loop through all possible credit cards that client accepts) { if(credit card type 1) { console.log("Not accepted credit card") continue } // here comes several more if checks and console.log() prints out whats happening } In this situation it really helps that you can clear content of console every time you try to validate inputted number. In my case for this validation there was about 5-6 different console.log() statements and i think the best way really is just to clear everything, i.e. not having to do any of the following: 1. console.log("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n") 2. console.log("----------------------------------------") 3. calling clear() directly in console I guess any complicated for statement, that you are calling a lot, with bunch of if statements inside where each prints out something via console.log(), is a valid case to use console.clear(). I'm not sure how to reopen this ticket, sooooo i would like to ask you guys to think about this one and reopen this ticket.
Pavel Feldman
Comment 4 2011-11-20 04:13:52 PST
Sure lets keep it open while we are addressing this issue. Did you consider using console.group/groupCollapsed/groupEnd? They would allow grouping nested entries that are issued while in the loop. Side note: you should not use console API in the production code.
Timothy Hatcher
Comment 5 2011-11-20 08:06:25 PST
You can also use console.group("some title") and console.groupEnd() for this, to group all related logs together.
Joseph Pecoraro
Comment 6 2014-08-05 12:09:44 PDT
console.clear() has been working for some time now!
Note You need to log in before you can comment on or make changes to this bug.