admin管理员组文章数量:1398578
I know that I can associate a popup.html to clicks on the extension button. However, I want it to be a menu, like the one popping up after clicking on Chrome's own "Customize and control Google Chrome" button (located to the right of your extension icons). I tried to Google it but no one seemed to be talking about that. Am I missing any mon sense about Chrome extension development?
I know that I can associate a popup.html to clicks on the extension button. However, I want it to be a menu, like the one popping up after clicking on Chrome's own "Customize and control Google Chrome" button (located to the right of your extension icons). I tried to Google it but no one seemed to be talking about that. Am I missing any mon sense about Chrome extension development?
Share Improve this question asked Jun 18, 2014 at 22:14 goldfrapp04goldfrapp04 2,3558 gold badges35 silver badges46 bronze badges2 Answers
Reset to default 4You can't.
You can either register a click via chrome.browserAction.onClicked
but show no UI, or open an HTML page in a popup. You can style it to look like a menu, but it will still not be like a native drop-down menu.
Note that you can right-click the extension button, but the menu you get there is fixed. I submitted a feature request a long time ago regarding that, but it never took off. There is a contextMenus
context "browser_action"
now that achieves this.
A practical example, since the documentation isn't actually that clarifying:
manifest.js
{
"name": "Foo menu",
"description": "Demonstrating context menus on browser actions",
"manifest_version": 2,
"version": "1.0",
"background": {
"persistent": false,
"scripts": ["background.js"]
},
"browser_action": {
"default_title": "Click me"
},
"icons": {
"16": "icon.png",
},
"permissions": ["contextMenus"]
}
background.js
chrome.contextMenus.removeAll();
chrome.contextMenus.create({
id: "FOO_ACTION",
title: "Foo",
contexts: ["browser_action"],
});
chrome.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === "FOO_ACTION") {
// Execute foo using tab id
foo(tab.id);
}
});
const foo = (tabId) => { console.log(`Foo called on tab with id ${tabId}`) };
本文标签: javascriptAdding dropdown menu to chrome extension iconStack Overflow
版权声明:本文标题:javascript - Adding drop-down menu to chrome extension icon - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744185717a2594281.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论