node.js - Debug a Javascript issue properly? (most likely client-side) -


this issue client-side, i'm not sure that. auction website , data (price, time left) every second websocket (node.js server).

if price changes, script automatically fires event countdown , price of auction flashes , array timers gets refreshed seconds left (auction.duration):

if ($('.price' + timers[i][0]).data('curr_text') !== $('.price' + timers[i][0]).text())  { $(".flashing" + timers[i][0]).toggle("highlight").toggle("highlight"); timers[i][1] = auction.duration;         } 

so, afk hours , of auction timers went 0 (shows 00:00:00), not timers. refreshed page, these auctions still running, client-side javascript problem. , huge problem, because user thinks auction over, refreshes page , notice it's still running.

i can guess issue occurs, because of timing issues, i'm not sure. don't know how debug issue, because can't stare on screen hours wait happen. appreciate suggestions debug this.

i think it's helpful show full code , maybe see i'm missing:

// prevent flashing after page loaded $(".refresh-item").each(function() { $this = $(this); var id = $this.attr("data-id");  $('.price' + $this.attr("data-id")).data('curr_text', $('.price' + id).text()); }); // format timer var formatseconds = function(secs){     var pad = function(n) {         return (n < 10 ? "0" + n : n);     };     var h = math.floor(secs / 3600);     var m = math.floor((secs / 3600) % 1 * 60); // reminder of hour of seconds x 60     var s = math.floor((secs / 60) % 1 * 60); // reminder of minute of seconds x 60     return pad(h) +":"+ pad(m) +":"+ pad(s); };    var timers = []; var socket = io.connect('http://xxx.rhcloud.com:8000/',{'forcenew':true }); socket.on('stream', function (data) {     $.each(data.streamarray,function(index,auction){         duration = auction.duration;     num_rows = data.streamarray.length;      if (duration > 0)     {     var price_retail = $("#" + auction.id).attr("data-retail");       var calc = auction.price.tofixed(2);     var price_calc = calc.tostring().replace(/\./g, ',');        $(".price" + auction.id).html(price_calc + "€");                 $(".discount" + auction.id).html(discount + "%");      if (timers.length < num_rows)     timers.push([auction.id, auction.duration]);     for(i in timers)      {                            if ($('.price' + timers[i][0]).data('curr_text') !== $('.price' + timers[i][0]).text())          {         $(".flashing" + timers[i][0]).toggle("highlight").toggle("highlight");         timers[i][1] = auction.duration;                 }     }        $('.price' + auction.id).data('curr_text', $('.price' + auction.id).text());             }      else     {     $(".sold" + auction.id).html("<div class='sold'>sold</div>").fadeout('fast').fadein('fast');                 }     }); }); function timercount() {     for(i in timers) {                       if(timers[i][1] <= 0) {         delete timers[i]; // if timer seconds less 1, delete it.         } else {                     timers[i][1]--; // else, decrease 1 second.         duration_html = formatseconds(timers[i][1]);                 $(".duration" + timers[i][0]).html(duration_html);                       }        } } setinterval(timercount, 1000); 

it's important mention red sign called "sold" appear if auction on (see end of socket stream). didn't happen. timer stopped , went 00:00:00. has array delete timers[i] triggered soon, guess?

additional information: forgot mention these timers reset approx. 15-16 seconds every time user placed bid. array timers alive long time. , array loops every single second.

as understand, timers got deleted every 1 minute code:

function timercount() {     for(i in timers) {                       if(timers[i][1] <= 0) {             delete timers[i]; // if timer seconds less 1, delete it.         } else {                         timers[i][1]--; // else, decrease 1 second.             duration_html = formatseconds(timers[i][1]);                     $(".duration" + timers[i][0]).html(duration_html);                       }        } } 

where decreasing minutes , hours?

and second thing - cannot guarantee time on client , server synchronized should perform ajax requests time in timers , adjust timers interval.


Comments