Can I add right-click options in Google Chrome?
There's a Context Menus API available in the developer and beta channels as of recently. You can use it to write your own extensions which add options to the right click menu. Note that this will only work for Google Chrome version 6 and higher.
Here's an example from the official extensions gallery:
- Imgur Uploader (upload an image to Imgur on right click)
I also wrote three of my own, based on that code:
- TinEye Right Click (perform a reverse image search at TinEye on right click)
- Wikipedia Right Click (search for articles about selected text at Wikipedia on right click)
- Merriam-Webster Right Click (look up definition of selected text at Merriam-Webster on right click)
You can install those at your own risk by right clicking the links, clicking Save Link As…, finding the files on your computer, and dragging them into a Google Chrome window.
Read about the API here:
- Context Menus
To write your own, you need a manifest.json file, which should look something like this:
{
"background_page": "background.html",
"description": "Add a context menu item to search for selected text at Google Maps.",
"icons": {
"16": "icon16.png",
"48": "icon48.png"
},
"minimum_chrome_version": "6",
"name": "Google Maps Right Click",
"permissions": [ "contextMenus", "tabs" ],
"version": "1.0"
}
You also need a background.html file, which should look something like this:
<script>
function searchgooglemaps(info)
{
var searchstring = info.selectionText;
chrome.tabs.create({url: "http://maps.google.com/maps?q=" + searchstring})
}
chrome.contextMenus.create({title: "Search Google Maps", contexts:["selection"], onclick: searchgooglemaps});
</script>
Lastly, you should have at least a 16 × 16 pixel icon for the context menu and a 48 × 48 pixel icon for the extensions management page. You can also specify a 128 × 128 pixel icon, which is shown during installation, and a 32 × 32 pixel icon if you want to submit your extension to the official gallery. All of your icons need to be listed in manifest.json. Make sure file types and names match up.
Put the icons, background.html, and manifest.json in a folder together, then go to the extensions management page at chrome://extensions
, look under Developer mode (I think you need to be running the beta channel or higher for this to show up), click on Pack extension…, next to Extension root directory click Browse…, locate and select the folder you made, click OK, and drag the resulting .crx file into your Google Chrome window.
Here's an extension that uses the Context Menus API to add options to the right click menu for selected text and lets you define your own custom searches.
- Context Menu Search
Try http://maps.google.com/maps?q=TESTSEARCH
for Google Maps and http://www.amazon.co.uk/s/?url=search-alias%3Daps&field-keywords=TESTSEARCH
for Amazon.co.uk.
There is a Context Search extension which does what you want with an exception that it does not add anything to the right click menu; instead, after you select a chunk of text on page, it will show a small button with blue triangle next to it, and clicking on it will pop up menu.