Add Styles to Console Statements
I was recently checking out Google Plus because they implement some awesome effects. I opened the console and same the following message:
WARNING!
Using this console may allow attackers to impersonate you and steal your information using an attack called Self-XSS.
Do not enter or paste code that you do not understand.
I wasn't surprised to see that message but what I did notice was that the text was red and the background was yellow. The text was even a bit bigger. How did they do it? Pretty easily:
console.log("%c%s",
"color: red; background: yellow; font-size: 24px;",
"WARNING!");
The first argument is the order of style and message, the second is the style set, and the last is the desired message.
As to why you'd want to use this? If it helps you identify debug information easier in the console, you may consider calling more attention to some messages!
![9 Mind-Blowing WebGL Demos]()
As much as developers now loathe Flash, we're still playing a bit of catch up to natively duplicate the animation capabilities that Adobe's old technology provided us. Of course we have canvas, an awesome technology, one which I highlighted 9 mind-blowing demos. Another technology available...
![Designing for Simplicity]()
Before we get started, it's worth me spending a brief moment introducing myself to you. My name is Mark (or @integralist if Twitter happens to be your communication tool of choice) and I currently work for BBC News in London England as a principal engineer/tech...
![WebKit Marquee CSS: Bringin’ Sexy Back]()
We all joke about the days of Web yesteryear. You remember them: stupid animated GIFs (flames and "coming soon" images, most notably), lame counters, guestbooks, applets, etc. Another "feature" we thought we had gotten rid of was the marquee. The marquee was a rudimentary, javascript-like...
![Jack Rugile’s Favorite CodePen Demos]()
CodePen is an amazing source of inspiration for code and design. I am blown away every day by the demos users create. As you'll see below, I have an affinity toward things that move. It was difficult to narrow down my favorites, but here they are!
Easy, if one controls the browser and therefor the console, that has to display this ;) But Firefox supports this as well, and only IE prints both, the format string as the string itself 1:1 into F12.
There’s a JS library that makes styling comments much easier:
https://github.com/astoilkov/console.message
By replacing your formatting placeholders with
%c%o
, it will output a readable repr for any type of object you pass in, not just the str value.https://jsfiddle.net/jsatt/Lta6p2jz/2/
very cool advice! my console is very colour ;)
With some trickery you can inject images too!
I find it amusing that this post starts with an example of a warning not to copy & paste code into the console, and ends with me wanting to copy & paste code from people’s comments into the console.
But it’s okay, cause I sort of understand it, right?
I like to put an object at the top of my script when I am developing to create a shortcut for styling my logs: