简体   繁体   中英

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.

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) {
 /// ...
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM