From 2cfbe447d2ac1be0cc946443642d653b4ba5ecab Mon Sep 17 00:00:00 2001 From: Rostyslav Nihrutsa Date: Thu, 19 Feb 2026 12:12:33 +0200 Subject: [PATCH] feat(sidebar): improve `isOpenSidebar` for available in Chrome --- src/sidebar.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/sidebar.ts b/src/sidebar.ts index db2e919..da08cc0 100644 --- a/src/sidebar.ts +++ b/src/sidebar.ts @@ -1,4 +1,5 @@ import {browser} from "./browser"; +import {getContexts} from "./runtime"; import {callWithPromise} from "./utils"; import type {FirefoxSidebarAction, OperaSidebarAction, SidebarAction} from "./types"; @@ -9,6 +10,7 @@ type OpenOptions = chrome.sidePanel.OpenOptions; type CloseOptions = chrome.sidePanel.CloseOptions; type PanelOptions = chrome.sidePanel.PanelOptions; type PanelBehavior = chrome.sidePanel.PanelBehavior; +type ContextFilter = chrome.runtime.ContextFilter; type IconDetails = opr.sidebarAction.IconDetails; // Available in Firefox and Opera @@ -141,8 +143,16 @@ export const setSidebarBehavior = (behavior?: PanelBehavior): Promise => sp.setPanelBehavior(behavior || {}, cb); }); -export const isOpenSidebar = (windowId?: number): Promise => - callWithPromise(async cb => { +export const isOpenSidebar = async (windowId?: number): Promise => { + if (sidePanel()) { + const filter: ContextFilter = {contextTypes: ["SIDE_PANEL"]}; + + if (windowId) filter.windowIds = [windowId]; + + return (await getContexts(filter)).length !== 0; + } + + return callWithPromise(async cb => { const sb = sidebarAction() as FirefoxSidebarAction | undefined; if (sb?.isOpen) { @@ -157,6 +167,7 @@ export const isOpenSidebar = (windowId?: number): Promise => throw new SidebarError("The sidebarAction.isOpen API is not supported in this browser"); }); +}; export const toggleSidebar = (): Promise => callWithPromise(async cb => {