Where are an addons keyboard shortcuts handled and how can they be traced?

How can the functions or messages which are executed by an addon’s shortcuts be traced, ie in the debugger?

Is there a standard or convention which determines what files contain the functions that are used or messages that are called by the shortcuts?

I want to know how the keyboards events in the TreeStyleTab addon are handled, ie the keyboard shortcuts customized on its preferences page.

In general TST will have to use https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/commands/onCommand somewhere for custom shortcut handling. It’s probably easier to look for it in the source code though: https://github.com/piroor/treestyletab/search?q=onCommand&unscoped_q=onCommand

1 Like

Thanks.

I will look into it.

Do you know how the Manage Extension Shortcuts modules in Firefox works, or the data structures it uses?

It is obvious that addons must present their functions to it for the keyboard shortcuts to be assigned to them.

How do you read the data structures it creates in debug mode?

I’m not sure I understand what you’re asking for or why you’re trying to find what you’re trying to find. Maybe describing your goal would help.

As you may be aware, all keyboard shortcuts of an extension are declared in its manifest: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/commands
which is what Firefox then uses to resolve the keyboard shortcuts, including the UI it presents you.

To see the manifest of an installed extension, go to about:debugging and click on the manifest URL for the extension you want to inspect the manifest of.

1 Like

I think this script is relevant, but haven’t tried to understand it: https://dxr.mozilla.org/mozilla-release/source/toolkit/mozapps/extensions/content/shortcuts.js

1 Like

In the TST source code the commands section shows the commands TST executes, but you will notice that not all of them have default shortcuts.

Some of them are empty and can be customized in either the Manage Extension Shortcuts page or the Keyboard Shortcuts section of the TST preferences.

What I’m interested in is the function that assigns shortcuts to commands at runtime when the user changes the shortcuts, and the in-memory data structures Firefox maintains for that purpose, not just for TST but for all other addons.

See my latest reply

Right, what I’m failing to understand is why you’re trying to find that.

The handling of the key events and redirecting to extensions as well as the resolving of keyboard shortcuts happens in https://dxr.mozilla.org/mozilla-central/source/toolkit/components/extensions/ExtensionShortcuts.jsm (which also uses most of the data structures you seem interested in? Though depending on what you’re trying to see, they may not be the ones in there at all…)

As you will find reading the code, this uses the XUL keyboard handling mechanism, which I have no idea where it would be, but it’s somewhere in mozilla-central too…

So I guess it really depends on what layer you care about these things.

This seems to what I am looking for.

My reasons are:

  1. I want leader keys to bring up a menu of commands I can run regardless of what addon it is. SurfkingKeys for instance presents a menu when you press a leader key like ‘y’ and already I am able to run some of TST’s commands in it. So if I add a set of keys for TST functions prefixed by ‘T’ for instance, I can add all TSTs commands and I don’t have to remember all its keyboard shortcuts.

  2. Seeing all the existing shortcuts at once is not possible because addons display only their shortcuts for modification, and Manage Extension Shortcuts only displays a few of them at a time. The Firefox UI does not enable you to see all of them at a go, and changing them is often trial and error because of conflicts.
    I need to see all of them in a single list at runtime and this is why I need those runtime data structures.

Is there a script that can go through the manifest.json files of all addons and list out their commands?

PS. I think I can do this myself if I master json. The important thing is learn from the API which addons are active and are compatible with the browser.

In what context? As an extension? As something running as Firefox chrome code? As something external to Firefox? etc.

Are you referring to 10 or 11.

What gives me the best control and integrates smoothly with my other work is all that matters to me. I can even send keystrokes from emacs if that makes it easier.

I pressed reply on Where are an addons keyboard shortcuts handled and how can they be traced?, so 11.