Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a custom item into the chrome context menu?

Is there any API to be used to add a custom item into the chrome context menu?

For example:

Now, I wanna add a "send to ..." item to context menu(right click), when it is clicked the contents selected in the webpage will be sent to someone.

I searched the chrome APIS and found that chrome.experimental.contextMenu is competent for my requirement, however it is experimental API so something like "path_to_chrome.exe --enable-experimental-extension-apis" will be added.

Any other solutions?

like image 743
pat.inside Avatar asked Dec 29 '22 12:12

pat.inside


2 Answers

Now (for long time) you have an option.

  1. Add this permission to your manifest.json file

    "permissions": ["contextMenus"]
    
  2. Then, something like that will do the trick:

    chrome.contextMenus.create({
      'title' : 'Open this select text %s',
      'contexts' : ['selection'],
      'onclick' : function(info, tab) {
         console.log('Selected link: ' + info.selectionText);
      }
    });
    

Good luck.

like image 103
Ido Green Avatar answered Jan 28 '23 21:01

Ido Green


Using contextMenu is the one and only way (outside of hacking on the Chromium source), but the API should be graduating from experimental when Google Chrome 6 gets released to the stable channel.

like image 23
oldestlivingboy Avatar answered Jan 28 '23 22:01

oldestlivingboy