Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add right click option to chrome extension's icon

Most of these questions seem to pertain to adding a right click to elements and pages using context menus. I would like to know if it is possible to add a right click option to a Chrome extension's icon. I.e. put an option such as "Documentation" between "Options" and "Disable"

like image 421
Rhyono Avatar asked Aug 23 '12 01:08

Rhyono


People also ask

How do I enable right click on Google Chrome?

On Chrome, go to 'Settings -> Privacy and Security -> Site Settings -> JavaScript' and then switch off the toggle. You can switch it back on any time you want.

How do I add a context menu to Chrome?

Use the chrome. contextMenus API to add items to Google Chrome's context menu. You can choose what types of objects your context menu additions apply to, such as images, hyperlinks, and pages.

How do you enable Right click in inspect element?

If the page you are on has a text or textarea input, click into this input (as if you want to enter text) then right-click and select 'Inspect element'. Show activity on this post. There you will find Enable right click. Click on it.


1 Answers

You can use Chrome create contextMenus API and set contexts="browser_action"

Example

chrome.contextMenus.create({
  "type":"checkbox",
  "checked":true,
  "title":"Connect via Cloud",
  "contexts":["browser_action"],
  "onclick":function(info, tab) {
      console.log(info);
  }
});
like image 127
MithooG Avatar answered Jan 31 '23 10:01

MithooG