Running a function in chrome extension on double click/select of a word
<p>I am trying to fire a notification whenever I double click on a word/select it. Found several examples online but I still cannot get my example working:</p>

<p>Manifest:</p>

<pre><code>{
  "name": "hh",
  "description": "hh!",
  "manifest_version": 2,
  "version": "0.0.0.1",
  "content_scripts": [
    {
      "matches": [ "http://*/*", "https://*/*" ],
      "js": [ "background.js" ],
      "all_frames": true,
      "run_at": "document_end"
    }
  ],
  "permissions": ["storage", "notifications"],
  "icons": { "128": "neoprice.png" }

}
</code></pre>

<p>background.js</p>

<pre><code>var listener = function(evt) {
    var selection = window.getSelection();
    if (selection.rangeCount &gt; 0) {
        displayPrice();
        var range = selection.getRangeAt(0);
        var text = range.cloneContents().textContent;
        console.log(text);
    }

};
document.addEventListener('dblclick', listener);

function displayPrice(){
  chrome.notifications.create(getNotificationId(), {
    title: "message.data.name",
    iconUrl: 'hh.png',
    type: 'basic',
    message: "message.data.prompt"
  }, function() {});
}

// Returns a new notification ID used in the notification.
function getNotificationId() {
  var id = Math.floor(Math.random() * 9007199254740992) + 1;
  return id.toString();
}
</code></pre>

<p>I was earlier adding the following but I saw people weren't using it, so I removed it</p>

<pre><code>  "app": {
    "background": {
      "scripts": ["background.js", "assets/jquery.min.js"]
  }
 },
</code></pre>

<p>What I am trying to achieve: Whenever they go to ANY page on selecting a word, it fires the function. Later, I wish to use this for a specific page. :)</p>

<p>Tried: <a href="https://stackoverflow.com/questions/20542340/how-to-keep-the-eventlistener-real-time-for-chrome-extensions">How to keep the eventlistener real time for chrome extensions?</a></p>

<p><a href="https://stackoverflow.com/questions/4007759/chrome-extension-double-click-on-a-word">Chrome extension double click on a word</a></p>

<p><a href="https://github.com/max99x/inline-search-chrome-ext" rel="nofollow noreferrer">https://github.com/max99x/inline-search-chrome-ext</a></p>

<p>Both don't really work as I want them too. :(</p>