javascriptgoogle-chrome-extensionopera-extension

Context menu in Chrome - two actions (left/right click on item menu)


I want to create an extension for chrome browsers: item menu in context menu with two different actions when you use left or right click on item menu. For Firefox it can be realized, but for Chrome? How?

enter image description here

background.js:

chrome.runtime.onInstalled.addListener(function() {
    chrome.contextMenus.create({
        title: 'do action (left cl. - first, right cl. - second)',
        id: 'test',
        contexts: ['link'],
    });
});
chrome.contextMenus.onClicked.addListener(function(info, tab) {
    if (info.menuItemId === "test") {
        console.log("first action completed")
    }
});

Solution

  • Distinguishing between two clicks in a context menu is impossible in Chrome.

    To be fair, it's a very confusing idea, I don't think people expect that from a context menu UI.

    Now, clicking with a modifier key is something more common (e.g. Delete vs Shift+Delete in a file manager), but Chrome does not support it either.

    You can see the full list of data available here.