title: Content Script: Uncaught TypeError: Cannot read property 'onRequest' of undefined
body: <p>I've been searching all over SO and reading through google docs but I can't seem to find a solution.</p>
  
  <p>My Chrome extension is injecting a content script and I want to set an <code>onRequest.listener</code> in order to sendRequests to the content script. This is <a href="https://stackoverflow.com/questions/2612098/about-sending-messages-among-bg-html-popup-html-and-contentscript-js"><em>the script</em></a> I used to for the <code>onRequest.listener</code>. The problem is I keep getting this error for some unknown reason. </p>
  
  <p>Error Message:</p>
  
  <p><code>Uncaught TypeError: Cannot ready property 'onRequest' of undefined</code></p>
  
  <p><code>contentscript.js line 1;</code></p>
  
  <p>Here's the relevant code...</p>
  
  <p><strong>Manifest.json</strong></p>
  
  <pre><code>{
    "name": "Injector Extension",
    "version": "1.0",
    "manifest_version": 1,
    "icons": { "128": "icon.png" },
    "browser_action": {
      "default_icon": "icon.png",
      "default_title": "Injector Extension",
      "default_popup": "popup.html"
    },
    "options_page": "options.html",
    "background": {
      "page": "background.html"
    },
    "permissions": [
      "tabs", 
      "http://*/*",
      "https://*/*",
      "unlimitedStorage"],
    "content_scripts": [{
          "matches": [" (injector specific url) "],
          "js": ["contentscript.js"]
    }],
    "web_accessible_resources": ["js/script.js"] 
  }
  </code></pre>
  
  <p><strong>content script</strong></p>
  
  <pre><code> chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
    if (request.method == "fromPopup") {
  
      // Send JSON data back to Popup.
      sendResponse({data: "from Content Script to Popup"});
  
    } else {
       sendResponse({}); // snub them.
    }
  });
  </code></pre>
  
  <p><strong>popup</strong></p>
  
  <pre><code>chrome.tabs.getSelected(null, function(tab) {
     chrome.tabs.sendRequest(tab.id, {method: "fromPopup", tabid: tab.id}, function(response) {
        console.log(response.data);
     });
  });
  </code></pre>