New issue
Advanced search Search tips
Starred by 20 users

Issue metadata

Status: Archived
Owner: ----
Closed: Aug 2015
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug



Sign in to add a comment

Javascript console.log does not log object instantly

Reported by andrew.b...@2ergo.com, Aug 2 2011

Issue description

Chrome Version       : 13.0.782.107 (Official Build 94237) beta
Other browsers tested:
  Firefox 3.5 (with firebug):   OK

What steps will reproduce the problem?
1. Create a page with the following javascript:
		var array = [1,2,3,4,5,6,7,8,9,10];
		var i = 0;
		while(array.length > 0) {
			console.log(i++, array);
			//alert("pause");
			array.pop();
		}
2. Open the page
3. View the Javascript Console log

What is the expected result?
The log should display:
0 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
1 [1, 2, 3, 4, 5, 6, 7, 8, 9]
2 [1, 2, 3, 4, 5, 6, 7, 8]
3 [1, 2, 3, 4, 5, 6, 7]
4 [1, 2, 3, 4, 5, 6]
5 [1, 2, 3, 4, 5]
6 [1, 2, 3, 4]
7 [1, 2, 3]
8 [1, 2]
9 [1]

What happens instead?
The log in fact displays:
1 []
2 []
3 []
4 []
5 []
6 []
7 []
8 []
9 []

Please provide any additional information below. Attach a screenshot if
possible.

It seems console.log does not use the object reference straight away, and instead logs it moments later (after it's been changed). If you uncomment the "alert" line everything works fine. This also seems to work fine from Firefox (with Firebug).

I either need console.log to log instantly (at the cost of blocking during the log), or make a copy of all objects, or a console.flush().

thanks
 

Comment 2 by shinyak@google.com, Aug 25 2011

I think fixing this bug is not so easy. Chrome's console can show the data structure using something like a tree view (try console.log(window)). I think this is a cool feature, so serializing a value into String to display is not an appropriate way. Another way is copying all objects, but copying a large object (such as window and document) causes significant performance slowdown. So I don't think we should adopt it.

The possible workaround for now is to insert toString() (or something like that) by a programmer. (e.g. console.log(a.toString())), I think.
Though this disables showing the data structure, you can get what you want.
Don't think it's a reason why Google did so. It worked for two years as it should and like everyone get used to. Why it was necessary to change console.log behavior after 12 versions of Chrome - I don't really know
Chrome should definitely clone the objects, but intelligently. If it sees window, document or circular references in a user-defined object, it should stop cloning. jQuery's extend skips cloning if it sees a DOM node or window.

I would hate to run into this during a long debugging session and not realize what Chrome is doing.
This issue is almost a year old now and i have run into it again. I hope we can atleast get some feedback from google saying if they are gonna change this or not.
Project Member

Comment 6 by bugdroid1@chromium.org, Aug 10 2012

Labels: -Pri-2 Pri-3 Action-NeedsReview
Status: IceBox
Due to the age of the issue, changing the priority to P3, however because it has at least 10 stars, marking it for review.

Comment 7 by laforge@google.com, Aug 10 2012

Status: Unconfirmed
Project Member

Comment 9 by bugdroid1@chromium.org, Mar 10 2013

Labels: -Area-Undefined
Status: Archived
Archiving unconfirmed issues, which have not been modified (commented on, updated, etc...) in over 2 years.

Sign in to add a comment