2808 explained code solutions for 75 technologies


chrome-extensionHow to add custom menu item to context menu


chrome.contextMenus.create({title: 'My menu', id: 'my_menu'});

chrome.contextMenus.onClicked.addListener(function (info, tab) {
  if (info.menuItemId = 'my_menu') {
    console.log(info);
  }
})ctrl + c
chrome.contextMenus.create

adds new menu item to context menu

'My menu'

title for new menu item

'my_menu'

id of new menu item to reffer to it later

onClicked.addListener

add listener for context menu click event

info.menuItemId = 'my_menu'

make sure our menu item is clicked

console.log(info)

do something when our menu item is clicked