Wierd json error with ie6

Hello,

First of all, please accept my apologies, because I’ll be talking about what could be a bug in the 1.2 js tracker (the json part) with ie6, but unfortunately, I was not yet able to set up a shareable test case (I really tried many scenari). Setting up a simple test case with only a dummy ajax call which also load jquery.json plugin before the tracker is not enough. Also, just removing the tracking code activation while keeping the piwik.js code loaded does trigger the bug, loading the js file is enough.

The issue is IE6 hangs on this part of the tracker code :


String.prototype.toJSON      =
            Number.prototype.toJSON  =
            Boolean.prototype.toJSON = function (key) {
                return this.valueOf();
            };

I’m using jquery to perform an ajax call in json format on that page, the error is only thrown when triggering the ajax call, the parent click event does work (apache logs shows that the ajax request in not performed though). The page is not using the piwik api, just the regular tracking code at the very bottom.

The error message thrown is :

using the ms debugger, I was able to locate the “guilty” bit :


return this.valueOf();

And it seems that it’s indeed the proper location (it’s not always simple to figure out such matter in ie6) since I can prevent this with a try/catch around that line.

Again, I’m not sure if the issue is indeed related to piwik, but since it’s working if I fully remove the tracking code or if I add the try/catch in the piwik.js code as mentioned above, it actually looks like there is some sort of conflict that could be solved in piwik.js code.

I have also tried to only load -http://demo.piwik.org/piwik.js to make sure it was not an issue with my local copy, with the same result.

Trying to further investigate the matter, I replaced the “guilty” line with :


$('#dbg').html('<pre>' + print_r(this,1) + '</pre>');

where print_r comes from phpjs.org, and got this as a result (if I try to print more than one level here, I get exactly [ERROR: [object Error]]) :


(object) :
 [onbeforeunload] : [WARNING: Too much recursion]
 [onafterprint] : [WARNING: Too much recursion]
 [top] : [WARNING: Too much recursion]
 [location] : [WARNING: Too much recursion]
 [parent] : [WARNING: Too much recursion]
 [offscreenBuffering] : [WARNING: Too much recursion]
 [frameElement] : [WARNING: Too much recursion]
 [onerror] : [WARNING: Too much recursion]
 [screen] : [WARNING: Too much recursion]
 [event] : [WARNING: Too much recursion]
 [clipboardData] : [WARNING: Too much recursion]
 [onresize] : [WARNING: Too much recursion]
 [defaultStatus] : [WARNING: Too much recursion]
 [onblur] : [WARNING: Too much recursion]
 [window] : [WARNING: Too much recursion]
 [onload] : [WARNING: Too much recursion]
 [onscroll] : [WARNING: Too much recursion]
 [screenTop] : [WARNING: Too much recursion]
 [onfocus] : [WARNING: Too much recursion]
 [Option] : [WARNING: Too much recursion]
 [length] : [WARNING: Too much recursion]
 [onbeforeprint] : [WARNING: Too much recursion]
 [frames] : [WARNING: Too much recursion]
 [self] : [WARNING: Too much recursion]
 [clientInformation] : [WARNING: Too much recursion]
 [external] : [WARNING: Too much recursion]
 [screenLeft] : [WARNING: Too much recursion]
 [opener] : [WARNING: Too much recursion]
 [onunload] : [WARNING: Too much recursion]
 [document] : [WARNING: Too much recursion]
 [closed] : [WARNING: Too much recursion]
 [history] : [WARNING: Too much recursion]
 [Image] : [WARNING: Too much recursion]
 [navigator] : [WARNING: Too much recursion]
 [status] : [WARNING: Too much recursion]
 [onhelp] : [WARNING: Too much recursion]
 [name] : [WARNING: Too much recursion]
 [$] : [WARNING: Too much recursion]
 [jQuery] : [WARNING: Too much recursion]
 [JSON2] : [WARNING: Too much recursion]
 [jQuery1509710070245585203] : [WARNING: Too much recursion]

As you can see, there is no valueOf method listed and I really don’t know why “this” seems to have become a jquery object or why this code is used by IE in the first place, since removing it does not break the rest of the process which already involves jquery with json.

Since there is a JSON2 object, I tried :


$('#dbg').html('<pre>' + print_r(this.JSON2,1) + '</pre>');

and got :


(object) :
 [stringify] : [WARNING: Too much recursion]
 [parse] : [WARNING: Too much recursion]

So it indeed seems that there is a conflict somewhere, but unfortunately, I just can’t find where it was “created” as everything works well with other decent browsers. I searched all my js files (and in line codes) to find out where (and how) “this” could have become a jquery object with no luck.

Now, since the whole matters occurs after the page fully loaded during a “click” event (the click even itself does work) triggering the ajax call (that triggers the error) this is also meaning that the tracking code has already executed, and thus that it should be “safe” to use try / catch to prevent the error in piwik.js.

But I really would prefer to understand this better, so if you are still reading here, I would really appreciate any type of hint you may think of about this issue.

No need to say that this is a pure IE issue, same code is working as expected with all other tested browsers.

Best regards, and thanks a lot already if you made it to read this rather long post about such an obscure one until the end.

dcz

We have fixed this in trunk. It’s a workaround for broken versions of prototype (pre-1.7) and mootools (pre-1.3).

I’m so glad you can’t imagine !

I just grabbed the json bit of piwik.js from the svn and now everything works as expected :)-D

I don’t use mootols nor prototype though, but the fix does work !

Thanks a lot!

dcz

If you’re not using prototype or mootools, then you have some other javascript library/framework that modifies the global object with a broken toJSON() method.

If it matters, the only two files that namely use a “toJSON” string in my whole project are jquery (1.5.1) and the jquery json plugin (2.2) from here : GitHub - Krinkle/jquery-json: [Discontinued] Use native JSON.stringify and JSON.parse instead, or json2.js from https://github.com/douglascrockford/JSON-js (excluding piwik files of course).

The interesting part being that while trying to put together a test case, I did try a simple scenario involving an ajax json call triggered by a click after I would use the jquery json plugin’s toJSON method to encode a simple object (my idea was to find out how guilty it could be) with no luck (well if we can say that for a working test case).

Anyway, I give up about understanding this one more in depth since it was only IE6 and is all working now.

Thanks again.

dcz