my initial problem was that I cannot open a chrome extension popup programatically by clicking on my contextMenu, so one workaround is using chrome.tabs.create in combination with chrome.windows.create and it works alright, but I figured if I make a shortcut for the extension, right now it is "Ctrl+Shift+K" combination and the popup opens and I simulate these three key being clicked in my eventHandler for the click on the contextMenu option my popup would open as well, but it has not worked so far.
background.js
chrome.contextMenus.create({
title: 'Testing',
contexts: ['selection'],
'id': 'Test_Selection'
});
chrome.contextMenus.onClicked.addListener(openPopupFromContextMenu);
function openPopupFromContextMenu() {
let ev = new KeyboardEvent('keypress', {
key: "k",
char: "k",
ctrlKey: true,
shiftKey: true
});
document.dispatchEvent(ev);
}
My shortcut is definitely working correctly and I have tried a thousand different methods of creating the event and dispatching it but it does not work. I tried with deprecated methods as well, because I was quite desperate. So if you have any tips for simulating these three button clicks and successfully dispatching them I'd be glad to hear them.Also I'd prefer pure JavaScript methods of doing so.
I tried something along the lines of
let e = new Event('keydown');
e.key = 'k';
e.keyCode = e.key.charCodeAt(0);
e.which = e.keyCode;
e.altKey = false;
e.ctrlKey = true;
e.shiftKey = true;
e.metaKey = false;
e.bubbles = true;
document.dispatchEvent(e);
but it was not working as well