0

I try to have a shortcut like Ctrl+Shift+0 in my webextension but it doesn't work !

The manifest.json:

    {
  "name": "Sample Commands Extension",
  "description": "Press Ctrl+Shift+U to send an event (Command+Shift+U on a Mac).",
  "manifest_version": 2,
  "version": "1.0",

  "commands": {
    "toto": {
      "suggested_key": {"default": "Ctrl+Shift+0" } ,
      "description": "Send a 'toggle-feature' event to the extension"
    }
  },

   "background": {
    "scripts": ["ts.js"]
  }
}

And (the file .js):

    browser.commands.onCommand.addListener(function(command) {
  if (command == "toto") {
    console.log("toggling the feature!");
    document.body.style.border = "5px solid red";
  }
});

But nothing happen !

It works when it is not a shortcut. Something blocks the shortcut ?

c523c
  • 9
  • 4
  • What exactly are you getting in the console! I tried it and I am getting `toggling the feature!` in my console!! What exactly is showing in your console? Btw I have Ubuntu. – Miraj50 Oct 09 '17 at 17:45
  • I have nothing in the console. It is like the key is not recognise, I tried a lot ! and the page doesn't be red too. – c523c Oct 09 '17 at 17:56
  • I hope you are not messing other trivial things. See the browser console by pressing Ctrl+Shift+J. The ts.js file and the manifest.json should be in the same folder together. Press `0` and not `O` . Are all of these things fine! Are you getting any error in the console? – Miraj50 Oct 09 '17 at 17:58
  • The console is opened. Same directory. I tried with F1, or ohers value, nothing works ! Adblock plus ? or other blocker ? – c523c Oct 09 '17 at 18:03
  • How to send ? you want the files ? – c523c Oct 09 '17 at 18:15
  • bad email address – c523c Oct 09 '17 at 18:25
  • yes, deamon return, bad address – c523c Oct 09 '17 at 18:50
  • 1
    It should be working, shortcuts with numbers were fixed in Firefox 55: https://bugzilla.mozilla.org/show_bug.cgi?id=1337545 I think your code will be wrong somewhere. All of your code will be needed to resolve your problem, maybe there is a syntax error somewhere. – Smile4ever Oct 09 '17 at 19:58
  • What, *exactly*, was shown in the [Browser Console](https://developer.mozilla.org/en-US/docs/Tools/Browser_Console) (Ctrl-Shift-J, or Cmd-Shift-J on OSX) when you tried to install and use the extension? – Makyen Oct 09 '17 at 22:55
  • There are [various appropriate consoles for your extension](https://stackoverflow.com/a/38920982/3773011). You should become familiar with them, as they are where you will see error information and any console output you choose to produce. – Makyen Oct 09 '17 at 22:55
  • `document.body.style.border` will do nothing in the background script. You need to use a [content script](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Content_scripts) to interact with a web page (e.g. manipulate the DOM, listen to clicks on the page, etc.). – Makyen Oct 09 '17 at 22:56
  • 1
    I suggest you read the [Anatomy of a WebExtension](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Anatomy_of_a_WebExtension) page (perhaps work through reading the pages linked from there). It has overall architecture information which should help your understanding of how things are generally organized/done. – Makyen Oct 09 '17 at 22:56
  • Makyen: my code comes from the doc and I don't need a web page, only to write something in the console. I read a lot the documentation. – c523c Oct 10 '17 at 03:38
  • Nothing happens in the console when I debug or launch the shortcut. – c523c Oct 10 '17 at 03:59
  • @Makyen, I suggest to read the [Setting up an extension development environment](https://developer.mozilla.org/en-US/Add-ons/Setting_up_extension_development_environment), too. There is several ways how to debug new extention in the FF. – Jasom Dotnet Oct 18 '17 at 06:02

0 Answers0