-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sidePanel
API: sidePanel.close()
and sidePanel.toggle()
#521
Comments
The sidePanel api is a bit weird really! |
Hello @fregante, thank you for your solution. Based on your solution, I think I've found a simpler way to implement the side panel toggle control. type OpenOptions = {
tabId: number;
windowId?: number;
};
const openSidePanel = async (payload: OpenOptions): Promise<void> => {
await chrome.sidePanel.open(payload);
};
const closeSidePanel = async () => {
// NOTE: don't pass the tabId, or this call may not work.
await chrome.sidePanel.setOptions({ enabled: false });
await chrome.sidePanel.setOptions({ enabled: true });
}; |
@Mr-haili Note that if you do use My function toggle () {
chrome.sidePanel.open()
chrome.runtime.sendMessage('closeSidePanel')
}
This is not ideal because it's the definition of a race condition. |
The sidePanel can be opened via
chrome.sidePanel.open()
but the API isn't symmetrical, there is no.close()
API.It would also be useful (maybe even more so) to just
.toggle()
the sidebar instead, using any trigger other than the action click, for example:menus.onClick
<button>
added on the pageAlternative to
chrome.sidePanel.close()
(✅ it works)As @dotproto pointed out, the sidebar can close itself via
window.close()
, so in other contexts you would have to set up messaging.You can also use
chrome.sidePanel.setOptions({enabled: false})
but that has undesired side effects (it removes it from the side panels list)Alternative to
chrome.sidePanel.toggle()
(⛔️ it doesn't work)This is more complicated because there's no easy way to determine whether the sidebar is open, so you'd have to add another listener and hope that this delay won't cause you to lose the user gesture permission:
Warning
I just tested this and it doesn't work:
Error:
sidePanel.open()
may only be called in response to a user gestureThe text was updated successfully, but these errors were encountered: