I'm creating an extension that will allow users to use chrome-like tab switching on Vivaldi browser.
In my background.js I have tried
addEventListener("keydown", function(e) { console.log(e.code); // never gets here }) I originally had the event being handled by a content.js script, however this required any new tabs to be completely loaded before I could send messages to the background.js script
function Listener() { this.stage = 0; this.listen(); } Listener.prototype.listen = function() { addEventListener("keydown", this.handleKeyDown); addEventListener("keyup", this.handleKeyUp); } Listener.prototype.handleKeyDown = function(event) { for(var i = 0; i < 9; i++) { if(event.ctrlKey) { if(event.code == "Digit" + (i + 1)) { chrome.runtime.sendMessage({ greeting: i }, function(response) { console.log(response); }) } } } } new Listener(); I want to move this functionality to my background.js so that it runs independently of browser actions.
chrome.commandsis for that purpose, though many limitation like all key combinations must include Ctrl or Alt, ....