Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>UPDATE</strong></p> <p>I just looked at the <a href="https://developer.chrome.com/extensions/contextMenus#method-create" rel="noreferrer">docs</a> and all this can be done much more simpler without any content scripts and callbacks:</p> <pre><code>chrome.contextMenus.create({ title: "Test %s menu item", contexts:["selection"], onclick: function(info, tab) { sendSearch(info.selectionText); } }); </code></pre> <p>That's all you need, because you can use <code>%s</code> in menu title to get selected text.</p> <p><em>(everything below is not needed anymore)</em></p> <hr> <p>Your <code>getSelection()</code> method doesn't return selected text, it just injects a content script to a page. Selected text is received sometime later in <code>onRequest</code> and then passed to a callback function from your callback array as a parameter.</p> <p>So this part:</p> <pre><code>var tx = getSelection(); var title = "Test '" + tx + "' menu item"; var id = chrome.contextMenus.create({"title": title, "contexts":[selection], "onclick": sendSearch(tx)}); console.log("selection item:" + id); </code></pre> <p>needs to be changed to something like this:</p> <pre><code>getSelection(function(tx) { var title = "Test '" + tx + "' menu item"; var id = chrome.contextMenus.create({"title": title, "contexts":["selection"], "onclick": sendSearch(tx)}); console.log("selection item:" + id); }) </code></pre> <p>But I would get rid of that <code>selection_callbacks</code> array altogether as I think it is not needed:</p> <pre><code>chrome.extension.onRequest.addListener(function (request) { var tx = request; var title = "Test '" + tx + "' menu item"; var id = chrome.contextMenus.create({"title": title, "contexts":["selection"], "onclick": sendSearch(tx)}); console.log("selection item:" + id); }); </code></pre> <p>Also note that <code>"contexts":[selection]</code> needs to be <code>"contexts":["selection"]</code>, and <code>"onclick": sendSearch(tx)</code> needs to be something like this instead:</p> <pre><code>"onclick": function(info, tab) { sendSearch(info.selectionText); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload