clear javascript console in Google Chrome
Update:
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.
How to clear the interpreter console?
As you mentioned, you can do a system call:
For Windows:
>>> import os
>>> clear = lambda: os.system('cls')
>>> clear()
For Linux it would be:
>>> import os
>>> clear = lambda: os.system('clear')
>>> clear()
How to remove all recent console command
If you want to clear the list of last typed commands, follow these steps:
(Step 1 and 2 are important, don't skip them!)
- Undock the console (click on the icon in the bottom-left corner, ).
(if you don't see , but , then hold the mouse pressed for a few seconds to get the desired icon) - Press Ctrl + Shift + J to open the console for this console. (On OSX use Cmd + Option + i)
- Go to the Resources tab, "Local Storage",
chrome-devtools://devtools
. Right-click on the item with key "consoleHistory", and choose "Delete".
Done! You may close the new console, and then dock the previous one if wanted. The console history will be gone when you reload the console.
If you just want to clear the console log (not the commands), just press Ctrl + L.
You could also use Incognito mode if you don't want to keep the list of commands you're going to type.
Node.Js on windows - How to clear console
console.log('\033[2J');
This works on linux. Not sure about windows.
You can "trick" the user using something like this:
var lines = process.stdout.getWindowSize()[1];
for(var i = 0; i < lines; i++) {
console.log('\r\n');
}
Clear terminal in Python
What about escape sequences?
print(chr(27) + "[2J")
Chrome console clear assignment and variables
Easiest way to clear data from the console is to refresh the page.
What you are affecting when declaring any variables or functions within the developer console is the global execution context, which for web browsers is window
.
When you clear()
the console you are telling Chrome to remove all visible history of these operations, not clear the objects that you have attached to window
.
How can I clear the terminal in Visual Studio Code?
Use Ctrl+K. This goes clean your console in Visual Studio Code.
Per comments, in later versions of VSCode (1.29 and above) this shortcut is missing / needs to be created manually.
- Navigate:
File
>Preferences
>Keyboard Shortcuts
- search for
workbench.action.terminal.clear
- If it has no mapping or you wish to change the mapping, continue; otherwise note & use the existing mapping
- Double click on this entry & you'll be prompted for a key binding. Hold
CTRL
and tapK
.Ctrl + K
should now be listed. Press enter to save this mapping - Right click the entry and select
Change when expression
. TypeterminalFocus
then press enter. - That's it. Now, when the terminal is in focus and you press Ctrl+K you'll get the behaviour you'd have expected to get from running
clear
/cls
.
Related Topics
What Is the Closest Thing Windows Has to Fork()
Unicode Encoding For String Literals in C++11
Why Copying Stringstream Is Not Allowed
What Happens If You Call Erase() on a Map Element While Iterating from Begin to End
Evaluating Arithmetic Expressions from String in C++
What Is the Performance Overhead of Std::Function
Catching Exception: Divide by Zero
How to Handle Wrong Data Type Input
Can You Use 2 or More or Conditions in an If Statement
Programmatically Find the Number of Cores on a Machine
C++ Deprecated Conversion from String Constant to 'Char*'
How to Emulate C Array Initialization "Int Arr[] = { E1, E2, E3, ... }" Behaviour With Std::Array
How to Implement Big Int in C++