title: Why is chrome.runtime undefined?
body: <p>I am creating a Google Chrome extension (my first one) and I want to send messages from the extension to the current tab.</p>
  
  <p>I am following the documentation:</p>
  
  <p><a href="https://developer.chrome.com/apps/runtime#event-onMessage" rel="noreferrer">https://developer.chrome.com/apps/runtime#event-onMessage</a></p>
  
  <p>The extension loads a small external JS into the tab's HTML, which contains the following code:</p>
  
  <pre><code>chrome.runtime.onMessage.addListener(
      function(request, sender, sendResponse) {
          console.log(request)
      }
  );
  </code></pre>
  
  <p>As soon as the JS is loaded I get the following error:</p>
  
  <p><code>Uncaught TypeError: Cannot read property 'onMessage' of undefined</code>.</p>
  
  <p>Opening console and typing <code>chrome</code>, I can see that the runtime is not a property of <code>chrome</code>.</p>
  
  <p>It looks like I am doing something wrong, but what? Do I need to add something to the <code>manifest.json</code> file?</p>
  
  <p>Chrome Version 39.0.2171.71 m</p>
  
  <p>Thank you.</p>