title: cant' add listener in chrome extension
body: <p>I'am trying to create chromium extension, but can't attach listeners to buttons in correct way. It must be noticed that I'am not very familiar with js, so mb the problem is in some missunderstanding conception or some element loading timing. </p>
  
  <pre><code>"background" : {"page" : "kbm.html"}
  </code></pre>
  
  <p>I'am using manifest v2, so inline js is disalowed, so i'am trying to add listeners in  callback</p>
  
  <p>here is kbm.html:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;script src="kbm.js"&gt;&lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;button id="loadall"&gt;Open all saved&lt;/button&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and here is kbm.js:</p>
  
  <pre><code>chrome.browserAction.onClicked.addListener(
          function(tab) {
              chrome.tabs.create( {'url': chrome.extension.getURL('kbm.html')}, 
                  function(tab) {
                      alert(document.getElementById("loadall"));
                         document.getElementById("loadall").addEventListener("click",loadAll,false);
                  });
          }
  );
  
  function loadAll(){
      alert("hallo");
  }
  </code></pre>
  
  <p>After loading kbm.html and clicking the toolbar icon I can see alert message from chrome.tabs.create callback. But click on loadall button gives nothing.</p>
  
  <p>I can see in debugger(with f12) that there is no listener on the button after page loading.</p>
  
  <p>The syntax is seems to be ok, because I can dynamically add listener to button from js-console </p>
  
  <pre><code>&gt;document.getElementById("loadall").addEventListener("click",loadAll);
  undefined
  </code></pre>
  
  <p>and it appears in element description so I see alert from loadAll() call after click.</p>
  
  <p>First I thougth that mb callback is called previous to all pages elements initialization and thus it can't find element with id="loadall", but acording to first alert with message</p>
  
  <pre><code>object HTMLButtonElement 
  </code></pre>
  
  <p>that is not the reason.</p>
  
  <p>But I still don't understand why there is no callback attached to button at page load:(</p>
  
  <p>I'v looked at examples but I cant blindly copy ther realisation I want to find what am I missing.</p>
  
  <p>Thanks in advance.</p>