Hi,
I'm working on a Google Chrome extension. In the popup I have the following code:
var bookmarks = [];
function appendBMTnode(node){
bookmarks.push([node[0].title, node[0].id]);
}
function addchildren(results){
for(x = 0; x < results.length; x++){
bookmarks.push([results[x].title, results[x].id]);
chrome.bookmarks.getChildren(results[x].id, addchildren);
}
}
function getallbookmarks(){
chrome.bookmarks.get('0', appendBMTnode);
chrome.bookmarks.getChildren('0', addchildren);
}
getallbookmarks();
console.debug(bookmarks.length);
console.debug(bookmarks);
Now, I would assume that the first command would issue the # of bookmarks I have. Indeed, when I use Chrome's debugger and add bookmarks.length to the watch list, 418 is the value. In the console of the debugger I can write bookmarks.length and it will give me the correct length. I can type
for(x = 0; x < bookmarks.length; x++){ console.debug(bookmarks[x]); }
and I get string representations of each inner array. However, that original console.debug(bookmarks.length)
gives an output of zero. And if I add console.debug(bookmarks[0]);
to the popup.html it tells me that the value is undefined.
But if I add the following to getallbookmarks()
(either first or last):
for(x = 0; x < 10; x++){
bookmarks.push(x);
}
then bookmarks.length will be 10 at first, and then 428. Also when I add the following function:
function printlen(){
console.debug(bookmarks.length);
}
and then in the body if I add
<a href="#" onclick="printlen()">test</a>
then I'll also get the proper bookmarks.length
value.
Any clue why the bookmarks objects won't register?