V
V
vzhicharra2017-09-01 22:38:54
Mozilla Firefox
vzhicharra, 2017-09-01 22:38:54

Extension for FF on WebExtexnsion on JS, doesn't see selectedtext?

Good afternoon!
I'm trying to write an extension for FF using the modern method, namely using the WebExtensionsAPI as described here:
the script itself is simple - by pressing the button (Alt + S) a window should open with a Google search for the selected text
, but for some reason this does not happen.
back.js:

browser.commands.onCommand.addListener(function(command) {

    if (command == "toggle-feature") {

        var selectedText = window.getSelection().toString().trim();
        console.log("selectedText:" + selectedText);
        browser.tabs.create({
        "url": "https://www.google.com/search?q="+selectedText

    });

    }
});

manifest.json:
{
  "name": "Sample Commands Extension",
  "description": "Press Alt+S to find in Google",
  "manifest_version": 2,
  "version": "1.0",
  "background": {
    "scripts": ["back.js"]
  },

  "commands": {
    "toggle-feature": {
      "suggested_key": { "default": "Alt+S" },
      "description": "Send a 'toggle-feature' event to the extension"
    }
  }
}

pieces of code honestly copied from their examples from here:
working with hotkeys
working with selected text
and if the script reacts to the key, then it doesn’t want to work with the selection
in the original where the handler hangs on releasing the mouse button (onmouse_up) and immediately copying to the clipboard,
but for me intercepting the event on pressing a combination of keys hangs,
but for some reason it doesn’t work with the buffer ...
the selected text does not even output to the console ...
somewhere there is a small jamb, I don’t understand where ...
thanks

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question