2

Sometimes when I'm using objects inside an userscript and using the TamperMonkey extension to run it, chrome's console.log() function is cached.
The code that effect it is this. The two console.log(save); always prints the same, although the will never be the same. However if I change console.log(save[testID]['lastCheck']); it will print differently.

function parseTestOverview(DOM)
{
    console.log(save);
    save[testID]['lastCheck'] = Date.now();
    var attempts = DOM.getElementsByClassName('answered');
    if(attempts.length == 0)
    {
        save[testID]['attempts'] = undefined;
        save[testID]['lastAttempt'] = undefined;
        save[testID]['lastAttempts'] = undefined;
        save[testID]['updated'] = false;
    }
    else if(save['lastAttempts'] || save['lastAttempts'] < attempts.length)
    {
        save[testID]['attempts'] = parseAttempts(attempts);
        var dateString = attempts[attempts.length - 1].innerText
            var dateTime = dateString.split(' ');
        var date = dateTime[0].split('-');
        var time = dateTime[1].split(':');
        save[testID]['lastAttempt'] = (new Date(date[2], date[1] - 1, date[0], time[0], time[1])).getTime();
        save[testID]['lastAttempts'] = attempts.length;
        save[testID]['updated'] = false;
    }
    else
    {
        save[testID]['updated'] = true;
    }
    GM_setValue('save', save);
    console.log(save);
    return attempts;
}

This may not make any out of context so here is the whole script: http://pastebin.com/u1qqCrt2

This may not make any sense either, because it is a site-specific script.

I'm running 15.0.859.0 canary on Mac OS X 10.7.1

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
Tyilo
  • 28,998
  • 40
  • 113
  • 198
  • You say "TamperScript" but you're really running TamperMonkey, yes? (The former normally is just a helper for installing scripts on the latter.) ... ... Please make a standalone demo of the problem that does not require a login! (Nor, ideally, Danish language skills. ;) ) ... ... Finally, `GM_setValue()` cannot store an object so easily in FireFox. It may be different in Chrome (I haven't tested yet) but that could be the problem. – Brock Adams Aug 23 '11 at 00:25
  • Yup I mean "TamperMonkey" and GM_setValue with objects seems to work in it. About making a standalone demo, I don't want to use hours to recreate the website and stuff. – Tyilo Aug 23 '11 at 00:30

1 Answers1

2

This is because webkit only shows the value of the object when it is expanded in the console, not when it is printed.

See also: https://stackoverflow.com/a/8249333/640584

Community
  • 1
  • 1
Tyilo
  • 28,998
  • 40
  • 113
  • 198