i want to learn to write chrome extensions. i am not new to programming at all, but quite new to javascript and web programming.

i want to use the chrome api to iterate over all open tabs. but my code results in crashing my whole browser.
i am on debian 7.5 using chromium 34 (latest update from the debian repository)

here is my code:

var tabinator = {
  fillBody: function() {
    chrome.tabs.query(
      {}, 
      function(tabs) { 
        for(var i=0; i<tabs.length; i++) { 
          alert(tabs[i].id);
        }
      }
    );
  }
};

// --- Execution starts here ---
document.addEventListener(
  'DOMContentLoaded', 
  function () {
    tabinator.fillBody();
  }
);

i did this tutorial, and used this reference.

can anyone help.

thanks in advance.

有帮助吗?

解决方案

thanks to Xan, he commented my Question an told me that i shouldn't call alert() within a popup-window. this was the problem, i now do it like this:

  fillBody: function() {
    chrome.tabs.query(
      {}, 
      function(tabs) { 
        for(var i=0; i<tabs.length; i++) { 
          document.write(tabs[i].title);
        }
      }
    );
  }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top