Capture keypress events before pageload ub WebExtension

Hi everyone,

the title pretty much says it all - is there a way to capture keypress events before the page is loaded using the web extensions API?

I am developing a custom keyboard shortcut extension, and this is something that I noticed is different from the old extension API.

Thanks,
Peter

There are two ways to add keybord listeners:

  • the commands thing in the manifest, but those can not be changed
  • content scripts, but those only work while the focus is inside a content page and the content script is loaded.

If your content script is executed to late, adding the runAt option should help.

Hi Niklas,

I see now, thanks for the tip. I’d like to be able to dynamically add/remove listeners while running, so adding the listener to the manifest is not the best option.

I did add the runAt option to the manifest. While it seems that the code executes a bit sooner, it’s still much worse (much later) than with xul addons (as it’s done here: https://github.com/oyvindio/skts).

On top of that, is there any way to make the code run on newtab page, about:* pages?

Thanks,
Peter

those only work while the focus is inside a content page and the content script is loaded

So, nope.

Well, bummer.
That makes webextensions subpar in comparison to xul addons.

Hope that gets fixed sometime…