Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I get the context Menu "oncreate" Event
    primarykey
    data
    text
    <p>I write a Chrome extension. This extension should add items to the Chrome context menü if a text is selected. This should happen dynamically everytime the contextmenu is opened.</p> <p>As on this image:</p> <p><img src="https://i.stack.imgur.com/ir5hF.png" alt="http://imgur.com/pJ5Fp"></p> <h1>The Problem:</h1> <p>I can't find any event that is triggered (and works) if the contextmenu opens. The following code sample doesn't work.</p> <blockquote> <p><code>window.addEventListener('contextmenu', function(){ DynamicMenu.generateMenu(window.getSelection()); });</code></p> </blockquote> <p>It's also impossible to trigger the adding of dynamic items from the "test" item:</p> <blockquote> <p><code>chrome.contextMenus.create( { "title": "test", "contexts" :["selection"], "onclick" : DynamicMenu.generateMenu });</code></p> </blockquote> <p>Thanks for your help!</p> <p><strong>Update</strong> (how it now works):</p> <p>Manifest:</p> <pre><code>... "content_scripts": [ { "matches": ["http://*/*", "https://*/*"], "js": ["document_event.js"], "run_at" : "document_idle" } ], ... </code></pre> <p>document_event.js:</p> <pre><code> window.addEventListener('mousedown', function(e) { var rightclick; if (!e) var e = window.event; if (e.which) rightclick = (e.which == 3); else if (e.button) rightclick = (e.button == 2); if(rightclick){ var searchText = window.getSelection().toString(); chrome.extension.sendRequest({search: searchText}, function(response) { ... }); } }); </code></pre> <p>content.js</p> <pre><code>... chrome.extension.onRequest.addListener( function(request, sender, sendResponse) { var a = request.search; ... sendResponse({}); }); ... </code></pre>
    singulars
    1. This table or related slice is empty.
    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. 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