title: Access NPAPI from pages DOM
body: <p>I'm attempting to override the default functionality for webkitNotifications.createNotification and via a Chrome extension I'm able to inject a script in the pages DOM that does so. Problem I'm having now is I need access to <code>chrome.extension.sendRequest</code> from the pages DOM in order to push my request to the NPAPI I have embedded in the background page. I previously had the embed object rendered on each page during the execution of the content-script - but believe it's more effective (and safe) if the NPAPI is embedded within the extension not injected on every page.</p>
  
  <pre><code>if (window.webkitNotifications)
  {
      (function()
      {
          window.webkitNotifications.originalCreateNotification = window.webkitNotifications.createNotification;
          window.webkitNotifications.createNotification = function (iconUrl, title, body) {
              var n = window.webkitNotifications.originalCreateNotification(iconUrl, title, body);
              n.original_show = n.show;
              n.show = function ()
              {
                  console.log("Chrome object", chrome);
                  console.log("Chrome.extension object", chrome.extension);
                  chrome.extension.sendRequest({'title' : title, 'body' : body, 'icon' : iconUrl});
              }
              return n;
          }
      })();
  }
  </code></pre>
  
  <p>That is what is injected in the DOM as a script element. The background page is as follows:</p>
  
  <pre><code>&lt;embed type="application/x-npapiplugz" id="plugz"&gt;
  &lt;script&gt;
  var osd = document.getElementById('plugz');
  
  function processReq(req, sender, callback)
  {
      osd.notify(req.title, req.body, req.image);
  
      console.log("NOTIFY!", req.title, req.body, req.image);
  };
  
  chrome.extension.onRequest.addListener(processReq);
  &lt;/script&gt;
  </code></pre>