8

I am wondering if I am able to modify the right-click menu of the browser action menu? I want to add an option titled 'Logout'.

Tomáš Hübelbauer
  • 9,179
  • 14
  • 63
  • 125
Jon
  • 2,249
  • 6
  • 26
  • 30

4 Answers4

14

For the context Chrome says:

Value must be one of: [all, page, frame, selection, link, editable, image, video, audio, launcher, browser_action, page_action]

So use

chrome.contextMenus.create({
  "title": "Logout",
  "contexts": ["browser_action"],
  "onclick": logout
});

Where logout() is the function that will be called when you click on it. (And enable "contextMenus" permission in the manifest.)

Edit: A bit of warning, if you have an Event page, using onclick attribute is not supported and you should add a chrome.contextMenus.onClicked handler instead.

Xan
  • 74,770
  • 16
  • 179
  • 206
user4139284
  • 141
  • 1
  • 3
  • 1
    To be fair: this answer is new, as this only hit Stable in Chrome 38. But that' is the **new correct answer**. – Xan Oct 14 '14 at 11:39
1

No you cant do that, youll need to stick it in the browser actions popup.

PAEz
  • 8,366
  • 2
  • 34
  • 27
0

It's now action context, not browser_action. Although I don't understand the difference and got no errors or warnings. Documentations says nothing. Thanks to https://stackoverflow.com/a/70209019/2630849

AlexWayfer
  • 39
  • 6
-3

hum, if i understand ... you want add item on menu after right click?

You can do this :

chrome.contextMenus.create({
  "title" : "You menu Name",
  "type" : "normal",
  "contexts" : ["link","video","audio"], //the context which item appear
  "onclick" : shorten() // The function call on click
});

And your manifest :

Add "contextMenus" on "permissions" array.

More information : here

Vincent Guesné
  • 776
  • 5
  • 13
  • 28