News for hackers. Stuff that matters.
Re:Chrome’s Console API: Greatest Hits by coolmitch on Friday April 03, 2015 @12:48PM (#9316910)
Author here-- really happy that people are finding this useful. I wrote it a few months ago when frustration with the way Chrome logged objects led me into their docs and I found a bunch of cool stuff I hadn't seen before.
Re:Chrome’s Console API: Greatest Hits by johnmaguire2013 on Friday April 03, 2015 @01:44PM (#9317256)
Excellent post, thank you!
Re:Chrome’s Console API: Greatest Hits by nailer on Friday April 03, 2015 @08:10AM (#9315408)
Re: caveats, if you want to snapshot something at a point in time but still have it look nice:

    console.log(JSON.stringify(someObject, null, 2))
Will nicely indent it for you.
Re:Chrome’s Console API: Greatest Hits by cleverjake on Saturday April 04, 2015 @02:38AM (#9320178)
two things about the `null` - the "replacer" function

1. in IE 8, it will choke. it needs to be a function (hopefully you don't have to care about IE 8, though)

2. in all other JSON.strigifable browsers, you can skip it with a falsey value, which is what the `null` is doing here. As a result, you can also use `0` (e.g. stringinfy(foo, 0, 2)), which I like because I can type it faster

Re:Chrome’s Console API: Greatest Hits by soyuka on Friday April 03, 2015 @03:34AM (#9314759)
The console api isn't really linked to chrome. I prefer the chrome debugging tool but those things should work on firefox too. I think you could be clearer on this point.
Re:Chrome’s Console API: Greatest Hits by tajen on Friday April 03, 2015 @04:17AM (#9314880)
Don't use that in prod, because it doesn't work in IE and it will cause your js to stop working.

In IE the 'console' object doesn't even exist if the developer tools aren't displayed, so if you use "console.log" in your program, your js will just throw an NPE.

Note that if you try closing the Developer Tools, 'console' is still declared for this page and all descendant pages. To test 'console.log' you need to avoid opening the devtools and open a new tabs.

Re:Chrome’s Console API: Greatest Hits by Encosia on Friday April 03, 2015 @09:02AM (#9315595)
I don't remember when exactly, but they fixed that at some point. I just ran this simple test in IE (without ever opening the dev tools) and got the alert: http://jsbin.com/hodavocuwu/1/edit
Re:Chrome’s Console API: Greatest Hits by deanclatworthy on Friday April 03, 2015 @05:55AM (#9315109)
The simple solution is to polyfill: https://github.com/paulmillr/console-polyfill
Re:Chrome’s Console API: Greatest Hits by ux-app on Friday April 03, 2015 @07:49AM (#9315330)
Another solution is to remove all debug commands as part of your build/deploy process.
Re:Chrome’s Console API: Greatest Hits by rmchugh on Friday April 03, 2015 @05:56AM (#9315110)
too right, extremely annoying bug, because when you open the dev tools to debug it, it starts working again!
Re:Chrome’s Console API: Greatest Hits by cleverjake on Friday April 03, 2015 @04:22AM (#9314891)
that hasn't been the case since IE 9
Re:Chrome’s Console API: Greatest Hits by tajen on Friday April 03, 2015 @04:27AM (#9314906)
This person is reporting it for IE10, do you have more insights? Do you think his IE was in compatibility mode? http://stackoverflow.com/questions/18480948/ie-10-debug-cons...
Re:Chrome’s Console API: Greatest Hits by cleverjake on Saturday April 04, 2015 @02:38AM (#9320180)
yep. compat mode.
Re:Chrome’s Console API: Greatest Hits by ahoge on Friday April 03, 2015 @08:59AM (#9315585)
> Don't use that in prod

A linter will catch this.

Re:Chrome’s Console API: Greatest Hits by ndesaulniers on Friday April 03, 2015 @12:19PM (#9316710)
Indeed, all of these are in Firefox, in Nightly at least. Though console.profile and console.profileEnd didn't seem to work? I'm sure someone from FF dev tools will turn up in this thread to clarify.
Re:Chrome’s Console API: Greatest Hits by jsantell on Friday April 03, 2015 @12:43PM (#9316872)
time/timeEnd, profile/profileEnd all work in Firefox up to Aurora -- current nightly has a new performance tool that will support profile/profileEnd in a few days, and will most definitely have it before uplift to Aurora https://bugzil.la/1077464
Re:Chrome’s Console API: Greatest Hits by gprasanth on Friday April 03, 2015 @08:16AM (#9315430)
console.copy is pretty useful to copy stuff to clipboard.
Re:Chrome’s Console API: Greatest Hits by jakub_g on Friday April 03, 2015 @08:50AM (#9315554)
Didn't know about that, thanks!

Note though it's not `console.copy` but `copy`; it's a part of Command Line API [1] which is not the same as Console API [2] - command line API is not accessible from JS of the page.

[1] https://developer.chrome.com/devtools/docs/commandline-api#c...

[2] https://developer.chrome.com/devtools/docs/console-api

Re:Chrome’s Console API: Greatest Hits by ndesaulniers on Friday April 03, 2015 @12:24PM (#9316749)
Looks like there's also:

* console.watch & console.unwatch

* console.timeline & console.timelineEnd

* console.timeStamp, console.time, console.timeEnd

* console.markTimeline

* console.groupCollapsed

* console.exception

In Firefox Nightly. A few of the timeline ones don't seem to work just yet, as the timeline is currently being prototyped in Nightly.

Re:Chrome’s Console API: Greatest Hits by jsantell on Friday April 03, 2015 @12:55PM (#9316942)
in Aurora (Fx39), profile/time tools create profiles and marks on the timeline, but nightly (Fx40) has a combined tool and the profile/profileEnd commands landing soon

watch/unwatch are from Object.prototype, confusingly enough!

Re:Chrome’s Console API: Greatest Hits by _ZeD_ on Friday April 03, 2015 @11:53AM (#9316538)
the "caveat" about "live" data is only in chrome console. For example firebug does not have this problem.

Another pet peeve of mine: at the moment, only in firebug I can call console.log() passing a function, get a nice, clickable function definition, that can get me directly to the "debugger" section, at the right place where the function is.

Re:Chrome’s Console API: Greatest Hits by Ginden on Friday April 03, 2015 @09:07AM (#9315614)
Simple, useful code (uses ES6 syntax) - `console.log({a, b, c, d})`- it's shortcut for `{a: a, b: b, c: c, d: d}` and is less invasive than breakpoint.
Re:Chrome’s Console API: Greatest Hits by nirkalimi on Friday April 03, 2015 @04:42AM (#9314938)
These look incredibly useful. Regardless if they work on IE or not.