Focus sidebar when it opens, and other things

I find that when I open sidebarAction window, I must click in it to get focus. Is there a way to focus the window when opens? I have tried window.focus() in the onload event, to no avail.

Related to that, is there a way to focus the sidebar when the mouse cursor is over it? I can detect mouseover event when the cursor enters the sidebar, and when doing so I can even “click” some of the elements using element.click() and they will trigger click listeners on elements inside the sidebar window, however, keydown event listeners on the sidebar window do not activate until I physically click with a mouse. Again, I have tried window.focus() in this scenario as well, to no avail.

Thanks…

1 Like

If you want to catch key inputs while the Firefox window but not your sidebar is focused, you can do that with the commands API.

Thank you, Niklas, but the Commands API won’t do what I want to do. I want to listen for the keydown of a single modifier key (alt key) and only that, display a dialog (based on where the mouse is hovering), then hide it when the user lifts up the key. The Commands API requires at least one modifier, and one non-modifier (from a limited subset). Unfortunately it is a “Commands” API, not a “Key Listener” API.

…and then I would still have the problem, “How do I get the sidebar to have focus without physically clicking on it?”

Does anyone know where I can find an answer to this? Especially, how to focus sidebar/sidebarAction window when it is opened? Do I need to file a bug?

Do I need to file a bug?

Yeah, I guess if there is no explicit API on browser.sidebarAction and window.focus() doesn’t work, I can’t think of any promising hack (Native Messaging would be overkill), I’d suggest you file a bug to request an API that allows to focus dfferent parts of the browser UI (unless there is one already)!

Thanks. How would one use native messaging for this?

Launch an application that listens for and forwards (OS-global) key events and/or “clicks” when desired.

But that requires the installation of a separate program and OS-specific implementations.

I actually have the code for the messaging itself and keyboard listeners for Windows (just “normal” keys plus optional modifiers, but only modifiers can’t be too hard) but I still think this would be overkill.

Oh yes, if it requires installing an external app, definitely overkill. Thanks!

Please upvote https://bugzilla.mozilla.org/show_bug.cgi?id=1502713.