javascriptfirefox-addonfirefox-addon-sdk

Problem with adding functionality to JavaScript Firefox Extension?


Works:

chrome.browserAction.onClicked.addListener(function (tabs) {
  if (allowedAddresses(tabs.url)) {
    chrome.tabs.sendMessage(tabs.id, { command: "getVideosArray" }, function (
      response
    ) {
      setIconBadgeTextFromValue(tabs.id, response);
    });
  }
});

But doesn't work when I want it to specify which mouse key was used:

chrome.browserAction.onClicked.addListener(function (tabs) {
  if (allowedAddresses(tabs.url) && OnClickData.button == 0) {
    chrome.tabs.sendMessage(tabs.id, { command: "getVideosArray" }, function (
      response
    ) {
      setIconBadgeTextFromValue(tabs.id, response);
    });
  }
});

Documentation: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/browserAction/onClicked

I'm using the supported version of firefox (85.0)

I'm trying it to eventually diferentiate between middle/left key or have it able to use "modifiers" to detect if the mouse was clicked with a modifier key pressed.


Solution

  • OnClickData is the second parameter passed to the callback function used for browserAction.onClicked.addListener. So the function definition for your callback should look like this:

    chrome.browserAction.onClicked.addListener(function (tabs, OnClickData) {
     /// ...
    });