Firefox extension popup sometimes needs to be clicked on to detect keyboard inputs

I made a simple calculator extension that can use keyboard inputs as an input method. The problem is that sometimes it will just take the inputs right away when I open the extension, but sometimes I need to click on the pop-up for it to start working. How would I go about fixing this issue?

The code handling the keyboard inputs looks like this:

document.addEventListener(‘DOMContentLoaded’, function() {
document.addEventListener(‘keydown’, (event) => {
switch (event.key) {
case 1: processInput(event.key); break;
// Cases for each input option
}
}
}

@Stereng, welcome to the Add-ons section of Discourse!

I think what you’re saying is that the extension’s popup doesn’t always receive focus after clicking the extension’s action button in the toolbar. Sometimes you have to manually focus the popup by clicking inside the popup’s document. Is that correct?

If so, it looks like these two bug reports may track the issue you’ve described:

If you have any additional information that may help Firefox contributors identify and fix the issue, you’re welcome to add it to the appropriate issue. Alternatively, if you just way to indicate that you’re also encountering this problem, you can use the Vote button under the “Details” section to +1 the issue.

Yes, that is correct. Thanks for responding! I guess it’s an issue with Firefox, rather than with my code.