I am developing a Chrome extension. How do you add a keyboard shortcut to open the sidepanel of this Chrome extension (using manifest v3)?
I have added this to manifest.json
:
"action": {
"default_popup": "profiles.html"
},
"side_panel": {
"default_path": "sidepanel.html"
},
"manifest_version": 3,
"commands": {
"_execute_action": {
"suggested_key": {
"default": "Alt+Y",
"mac": "Alt+Y"
}
},
"open_side_panel": {
"suggested_key": {
"default": "Alt+W",
"mac": "Alt+W"
},
"description": "Open the side panel"
}
},
"background": {
"service_worker": "background.js"
}
And I have this in background.js
:
chrome.commands.onCommand.addListener((command) => {
if (command === "open_side_panel") {
chrome.sidePanel.setOptions({
path: 'sidepanel.html'
});
chrome.sidePanel.show();
}
});
I have thoroughly tested it: Alt+W does not open the side panel of my extension. Alt+Y opens the popup of the extension though.
I have also tested with this in background.js
:
chrome.commands.onCommand.addListener((command) => {
if (command === "open_side_panel") {
chrome.tabs.create({
url: chrome.runtime.getURL('sidepanel.html')
});
}
});
The keyboard shortcut Alt+W then works, but it opens a new tab with my Chrome extension side panel webpage, it is not opening the side panel in the sidebar.
Is it possible to open a Chrome extension sidepanel with a keyboard shortcut? I am asking because I use Chrome v126.0.64 (fully uptodate)v and there is no sidebar icon any more by default. I have added it back and use it daily for some extensions like Raindrop:
enter image description here