Posts Tagged ‘javascript’

Automatically Format Any Javascript Code

Sunday, June 21st, 2009

Every javascript programmer at somepoint finds themself in a situation where they need to undo the effects of a packer or minifier on their code. Javascript Beautifier to the rescue.

Javascript Beautifier

It lets you cleanup the super scrunched up code into something more readable. This enables you to recover your source files if you lost your originals or dig through someone elses code and get a better idea of how other people in the real world are coding.

Passpack + Chrome = Frustration

Saturday, June 20th, 2009

Everyday I log into Passpack and leave it open all day. So here’s the problem after having Passpack open for a while I get the following message (it is extremely annoying as it interupts whatever else your up to on the net). This only happens for me in Chrome. It works like butter in Firefox and I can’t speak for IE.

Passpack History Problem

The initial trigger for the message seems to be random. But after it initial message is seems to come back around every 3 minutes. So I did some digging. After poking around in the source I discovered that they’re using an older version of Tako Sano’s jQuery history plugin.

So I added some code to the historyCallback do some logging so I could get a better feel for what was going on.

4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
errorOccurred = lastErrorOccurred = new Date().getTime();
_back = function(h) {
    if (_backOk) {
        if (_backCallback) {
            _backCallback();
            _backCallback = null;
        }
        var hh = parseInt(h);
        var m = $.browser.netscape ? 2 : $.browser.msie ? 3 : 7;
        if (hh > m) {
            errorOccurred = new Date().getTime();
            console.log("hh: "+ hh +", m: "+ m +", delta: "+ (errorOccurred - lastErrorOccurred));
            lastErrorOccurred = errorOccurred;
            alert(PP.msg.man.bac);
        }
    }
};

After letting this run for a while I started to see a pattern. Here’s an excerpt of the results.

  • hh: 8, m: 7, delta: 209901 (~3.4 minutes)
  • hh: 8, m: 7, delta: 200888 (~3.3 minutes)
  • hh: 8, m: 7, delta: 190944 (~3.2 minutes)
  • hh: 8, m: 7, delta: 183514 (~3.0 minutes)
  • hh: 8, m: 7, delta: 197517 (~3.3 minutes)

For webkit (Chrome/Safari) based browsers the jQuery history plugin manually creates a stack to keep track of the history. So this is where I believe we are encountering the problem. If you look at line 4426 you can see that we create a history with a stack length of 9.

4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
_back = function(h) {
    if (_backOk) {
        if (_backCallback) {
            _backCallback();
            _backCallback = null;
        }
        var hh = parseInt(h);
        var m = $.browser.netscape ? 2 : $.browser.msie ? 3 : 7;
        if (hh > m) alert(PP.msg.man.bac);
    }
};
runHistory = function() {
    $.historyInit(_back);
    z = $.browser.netscape ? 2 : $.browser.msie ? 4 : 8;
    for (var j = z; j >= 0; j--) $.historyLoad(j);
    _SetTimeout(function() {
        _backOk = 1
    },
    3000);
};

But on line 4419 we are working with a stack with a length of 8.

4419
        var m = $.browser.netscape ? 2 : $.browser.msie ? 3 : 7;

Shouldn’t this read as follows?

4419
        var m = $.browser.netscape ? 2 : $.browser.msie ? 4 : 8;