Chrome Extension - Modify Right-Click Browser Action Menu
Asked Answered
W

4

9

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'.

Welterweight answered 25/3, 2012 at 20:24 Comment(0)
W
1

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

Warily answered 26/3, 2012 at 6:11 Comment(2)
Darn it. Thanks for letting me know though :)Welterweight
Now possible; updated information in this answer.Cry
A
15

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.

Allembracing answered 13/10, 2014 at 22:23 Comment(1)
To be fair: this answer is new, as this only hit Stable in Chrome 38. But that' is the new correct answer.Cry
W
1

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

Warily answered 26/3, 2012 at 6:11 Comment(2)
Darn it. Thanks for letting me know though :)Welterweight
Now possible; updated information in this answer.Cry
D
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://mcmap.net/q/1314826/-add-contextmenu-items-to-a-chrome-extension-39-s-browser-action-button-manifest-v3

Diondione answered 31/8, 2023 at 10:30 Comment(0)
E
-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

Erechtheum answered 26/3, 2012 at 20:17 Comment(1)
No, you don't understand. Jon asked about the browser action menu, not the page context menu.Sissy

© 2022 - 2024 — McMap. All rights reserved.