开发者

Google Chrome Context Menu's

I can't tell from google's doc's 开发者_Python百科and the sample they provide if the context menu for chrome extensions can be used for the bookmarks bar.

Has anyone had any experience with this? Thanks.


If you are asking whether or not you can add a new item to a context menu that appears when you right click on a bookmark bar, then the answer is unfortunately no, you can modify only web page context menu.


As of 2020 you can not for the bookmark bar. Exposing context menus from extensions on the address bar is possible. Also, you can add context menus to work in Chrome, on every page, and your question title lead me here so let me answer for others. There's samples (02.02.2020): https://developer.chrome.com/extensions/samples#search:contextmenus

Basically, you want to make your own extension and your context additions will show in context menu. Here's a super simple starter (the documentation says "manifest_version": 2 (so that is not a reflection of my project versioning). Perhaps most pertainent to the OP's question is the "permissions": ["contextMenus"] (there's a bunch other permissions for extensions, but this is the one we want for a simple right-click add-on:

manifest.json

{
    "name": "Lil Click, Long Way",
    "description": "Ipsum dolor foo bar baz.",
    "version": "0.1.0",
    "permissions": [
        "contextMenus"
    ],
    "background": {
        "persistent": false,
        "scripts": [
            "my-context.js"
        ]
    },
    "manifest_version": 2
}

my-context.js

// contexts: all, audio, browser_action, editable, frame, 
//   image, launcher, link, page, page_action, selection, video
// types: checkbox, normal, radio, separator
chrome.contextMenus.create({
    "title": "FOOBAR",
    "id": "my-context-item", 
    "contexts": ["all"], 
    "type": "normal"
});

NOTE the above doesn't actually handle any clicks or anything. I'm just illustrating getting a context menu item to show up.

Add your extension to Chrome with: Extensions -> Developer Mode 'ON' -> Load Unpacked (and point to directory where these two files live):

Google Chrome Context Menu's

I'm still brand new to this, but it appears "all" will make it show in both text box inputs and wherever else on the DOM. Other settings seem to limit it... I'd suggest looking up docs.

Google Chrome Context Menu's

Google Chrome Context Menu's

Google Chrome Context Menu's

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜