title: Message passing in Chrome Extension
body: <p>I am quite confused about the what are counted as chrome extension view, which directly linked to what function I can use for passing messages between different components.</p>
  
  <p>Let me just describe what I am trying to do first;</p>
  
  <p>My background.html creates Desktop Notifications based on some events received from a node.js server through socket.io.</p>
  
  <p>When the user clicks on the notification, I want to create a new tab pointing to a html within my extension (/src/view/token.html), and then send some data from the background.js (where my socket.io codes are) to the new tab. And I want to do this through message passing.</p>
  
  <p>So, basically, i am doing</p>
  
  <pre><code> var notification = webkitNotifications.createNotification(image, title, content);
   notification.onclick(function(e){
  
      chrome.tabs.create({url: "/src/view/tokens.html"}, function(tab){
          //just to make sure the tab is activated..
          chrome.tabs.onUpdated.addListener(function(tabId){
              if(tabId == tab.id) {
                  chrome.tabs.sendMessage({data: whatever_data}, tabId); 
              }
          });
      });
  
   });
  </code></pre>
  
  <p>Now my problem is in my tokens.js (loaded in tokens.html), I try to listen for the message using:</p>
  
  <pre><code>chrome.extension.onMessage.addListener(function (msg, _, sendResponse) {
  console.log(msg);
  });
  </code></pre>
  
  <p>but I am getting "Uncaught TypeError: Cannot read property 'onMessage' of undefined:, so I assume that I don't have access to chrome.extension in the tokens.html??? </p>
  
  <p>I tried this with popup page (browser action popup) and option page, and they all worked just fine. So, I guess the view I created is just not a chrome extension page?</p>
  
  <p>Now I am confused... 
  1) What are considered as chrome extension pages that have access to the chrome.* API
  2) How should I implement what I want to do? </p>
  
  <p>Thanks!</p>