Click here to Skip to main content
15,868,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
im working on a content script in chrome and after several hours of trying to debug a strange problem that caused my current tab to crash, i'm still quite puzzled. it seems that this piece of code runs without crashing the tab:

for (var id in newDeleted) {
  var nameTile = document.createElement("LI");
  innerListElement.appendChild(nameTile); //<======= 
  nameTile.innerHTML = newDeleted[id]["name"] + "<br/>";
  var imgTile = document.createElement("IMG");
  imgTile.src = newDeleted[id]["img"];
  nameTile.appendChild(imgTile);
}

while this doesn't:

for (var id in newDeleted) {
  var nameTile = document.createElement("LI");
  nameTile.innerHTML = newDeleted[id]["name"] + "<br/>";
  var imgTile = document.createElement("IMG");
  imgTile.src = newDeleted[id]["img"];
  nameTile.appendChild(imgTile);
  innerListElement.appendChild(nameTile);//<======= 
}

moreover, i found out that this indeed wroks:

   for (var id in newDeleted) {
  var nameTile = document.createElement("LI");
  nameTile.innerHTML = newDeleted[id]["name"] + "<br/>";
  var imgTile = document.createElement("IMG");
  imgTile.src = newDeleted[id]["img"];
  nameTile.appendChild(imgTile);
  console.log(nameTile);//<=========== 
  innerListElement.appendChild(nameTile);//<======= 
}


im trying to find out if appendChild takes some time to load but i can't see any evident that you need to be careful with it and wait till it finish to load. can someone please explain to me what is going on?
Posted
Updated 15-Sep-14 0:11am
v3
Comments
Dennis E White 15-Sep-14 11:06am    
via the chrome developer tools have tried setting a break point in your code and then inspecting what innerListElement actually is??
yno1 16-Sep-14 11:55am    
the innerListElement is defined in the upper scope as:
var innerListElement = document.createElement("LI");

that is...there is nothing to track of.
BTW im starting to think that my first Impression about the switching of the lines is not the cause of the problem...im thinking now that the problem is actually the console. is it possible?
it seems like only when the chrome console is open my tab crashes. but im not sure.
the only thing that i sure of is that the problematic line is innerListElement.appendChild(nameTile) but i don't know why sometimes it works and sometimes not.
Dennis E White 16-Sep-14 12:00pm    
use the chrome developer tools and set a break point in the code so you can inspect everything.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900