While working on Bookee, I discovered some strange behaviour with respect to keyboard shortcuts to activate Chrome (and likely Web) Extensions.
When the scope for a Chrome or Web Extension is set to
Global
(rather than Chrome
), the
background script (or worker script for mv3) can have
trouble detecting whether the current page is the new-tab
page.
I wrote about the Global Shortcut earlier, which provides more context on how to allow your extension users to change a keyboard combination's scope.
I'm still working on diagnosing why the change of scope causes issues with the tab URL detection. More to come.
Updates
-
Turns out this was a bit of a
changing a lightbulb
experience. It took me a while to figure it all out. The
root of the issue was that the extension didn't have
access to the
url
property for all tabs. -
The reason this problem only showed up with the global
shortcut was because I could read the
url
property for a focused tab. But since the global shortcut was being triggered from outside Chrome, I don't believe that the concept of a "focused tab" actually existed. -
Anyway, to get around this, I needed to request the
tabs
permission in mymanifest.json
file, and re-architect a few things around command event listeners.