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!
![Camera and Video Control with HTML5]()
Client-side APIs on mobile and desktop devices are quickly providing the same APIs. Of course our mobile devices got access to some of these APIs first, but those APIs are slowly making their way to the desktop. One of those APIs is the getUserMedia API...
![Introducing MooTools Templated]()
One major problem with creating UI components with the MooTools JavaScript framework is that there isn't a great way of allowing customization of template and ease of node creation. As of today, there are two ways of creating:
new Element Madness
The first way to create UI-driven...
![Chris Coyier’s Favorite CodePen Demos]()
David asked me if I'd be up for a guest post picking out some of my favorite Pens from CodePen. A daunting task! There are so many! I managed to pick a few though that have blown me away over the past few months. If you...
![9 Incredible CodePen Demos]()
CodePen is a treasure trove of incredible demos harnessing the power of client side languages. The client side is always limited by what browsers provide us but the creativity and cleverness of developers always pushes the boundaries of what we think the front end can do. Thanks to CSS...
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: