admin管理员组文章数量:1127654
I was wondering if I could clear up the console with some command..
console.log()
, can print... is there a command to clear up console?..
I've tried to console.log(console);
and got this functions below...
assert: function assert() { [native code] }
constructor: function Console() { [native code] }
count: function count() { [native code] }
debug: function debug() { [native code] }
dir: function dir() { [native code] }
dirxml: function dirxml() { [native code] }
error: function error() { [native code] }
group: function group() { [native code] }
groupEnd: function groupEnd() { [native code] }
info: function info() { [native code] }
log: function log() { [native code] }
markTimeline: function markTimeline() { [native code] }
profile: function profile() { [native code] }
profileEnd: function profileEnd() { [native code] }
time: function time() { [native code] }
timeEnd: function timeEnd() { [native code] }
trace: function trace() { [native code] }
warn: function warn() { [native code] }
__proto__: Object
[ I guess there's no way to clear up the console... but I wanted someone to say it to me... ]
I was wondering if I could clear up the console with some command..
console.log()
, can print... is there a command to clear up console?..
I've tried to console.log(console);
and got this functions below...
assert: function assert() { [native code] }
constructor: function Console() { [native code] }
count: function count() { [native code] }
debug: function debug() { [native code] }
dir: function dir() { [native code] }
dirxml: function dirxml() { [native code] }
error: function error() { [native code] }
group: function group() { [native code] }
groupEnd: function groupEnd() { [native code] }
info: function info() { [native code] }
log: function log() { [native code] }
markTimeline: function markTimeline() { [native code] }
profile: function profile() { [native code] }
profileEnd: function profileEnd() { [native code] }
time: function time() { [native code] }
timeEnd: function timeEnd() { [native code] }
trace: function trace() { [native code] }
warn: function warn() { [native code] }
__proto__: Object
[ I guess there's no way to clear up the console... but I wanted someone to say it to me... ]
Share Improve this question edited Jun 10, 2010 at 4:18 Samuel Neff 74.8k18 gold badges143 silver badges186 bronze badges asked Jun 10, 2010 at 4:16 Reigel GallardeReigel Gallarde 65.2k21 gold badges124 silver badges141 bronze badges 1- Related posts - How to clear Chrome console by shortcut keys? & How to remove all recent console command – RBT Commented Jun 21, 2019 at 2:14
19 Answers
Reset to default 330Update:
console.clear()
is available in all browsers
Update: As of November 6, 2012,
console.clear()
is now available in Chrome Canary.
If you type clear()
into the console it clears it.
I don't think there is a way to programmatically do it, as it could be misused. (console is cleared by some web page, end user can't access error information)
one possible workaround:
in the console type window.clear = clear
, then you'll be able to use clear in any script on your page.
There's always the good ol' trick:
console.log("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
or a shorter variation of the above:
console.log('\n'.repeat('25'));
Not the most elegant solution, I know :) ... but works.
For me, I usually just print a long "-----" separator line to help make the logs easier to read.
This seems to work just fine:
console.clear();
If you use console.clear()
, that seems to work in chrome. Note, it will output a "Console was cleared" message.
Note, I got an error right after clearing the console, so it doesn't disable the console, only clears it. Also, I have only tried this in chrome, so I dont know how cross-browser it is.
EDIT: I tested this in Chrome, IE, Firefox, and Opera. It works in Chrome, MSIE and Opera's default consoles, but not in Firefox's, however, it does work in Firebug.
If you want to just clear the console when debugging, you can simply click the "ban-circle" ⃠
button to clear console.log.
Alternatively just press "Ctrl+L" to clear the console using your keyboard.
Chrome:
console._commandLineAPI.clear();
Safari:
console._inspectorCommandLineAPI.clear();
You can create your own variable, which works in both:
if (typeof console._commandLineAPI !== 'undefined') {
console.API = console._commandLineAPI;
} else if (typeof console._inspectorCommandLineAPI !== 'undefined') {
console.API = console._inspectorCommandLineAPI;
} else if (typeof console.clear !== 'undefined') {
console.API = console;
}
After that, you can simply use console.API.clear()
.
you can use
console.clear();
if you are working with javascript coding.
else you can use CTR+L
to clear cosole editor.
Press
CTRL+L
Shortcut to clear log
, even if you have ticked Preserve log
option.
Hope this helps.
On the Mac you can also use ⌘+K
just like in Terminal.
Instead of typing command just press:
CLTRL + L
to clear chrome console
A handy compilation of multiple answers for clearing the console programmatically (from a script, not the console itself):
if(console._commandLineAPI && console._commandLineAPI.clear){
console._commandLineAPI.clear();//clear in some safari versions
}else if(console._inspectorCommandLineAPI && console._inspectorCommandLineAPI.clear){
console._inspectorCommandLineAPI.clear();//clear in some chrome versions
}else if(console.clear){
console.clear();//clear in other chrome versions (maybe more browsers?)
}else{
console.log(Array(100).join("\n"));//print 100 newlines if nothing else works
}
console._inspectorCommandLineAPI.clear()
That is working
On the Chrome console right click with the mouse and We have the option to clear the console
I use the following to alias cls
when debugging locally in Chrome (enter the following JavaScript into the console):
Object.defineProperty(window, 'cls', {
get: function () {
return console.clear();
}
});
now entering cls
in the console will clear the console.
Chrome - Press CTRL + L while focusing the console input.
Firefox - clear()
in console input.
Internet Explorer - Press CTRL + L while focusing the console input.
Edge - Press CTRL + L while focusing the console input.
Have a good day!
Based on Cobbal's answer, here's what I did:
In my JavaScript
I put the following:
setInterval(function() {
if(window.clear) {
window.clear();
console.log("this is highly repeated code");
}
}, 10);
The conditional code won't run until you ASSIGN window.clear (meaning your log is empty until you do so). IN THE DEBUG CONSOLE TYPE:
window.clear = clear;
Violà - a log that clears itself.
Mac OS 10.6.8 - Chrome 15.0.874.106
On MacOS:
- Chrome - CMD+K
- Safari - CMD+K
- Firefox - No shortcut
On Linux:
- Chrome - CTRL+L
- Firefox - No shortcut
On Windows:
- Chrome - CTRL+L
- IE - CTRL+L
- Edge - CTRL+L
- Firefox - No shortcut
To make it work in Firefox, userscripts
can be used. Download GreaseMonkey
extension for FF.
document.addEventListener("keydown",function(event){
if(event.metaKey && event.which==75) //CMD+K
{
console.clear();
}
});
In the script, update the metadata with the value, //@include *://*/*
, to make it run on every pages. It will work only when the focus is on the page. It's just a workaround.
I think this is no longer available due to 'security issues'.
console.log(console)
from code gives:
Console
memory: MemoryInfo
profiles: Array[0]
__proto__: Console
From outside of code, _commandLineAPI is available. Kind of annoying because sometimes I want to just log and not see the old output.
I'm going to add to this, as it's a search that came out top on google..
When using ExtJS / Javascript I insert this and the console is cleared out - unless there is an error..
console.log('\033[2J');
I'm more than likely way off course, but this is how I clear the console for each page load/refresh.
本文标签: clear javascript console in Google ChromeStack Overflow
版权声明:本文标题:clear javascript console in Google Chrome - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736705966a1948679.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论