Calling sidebarAction.close gives error

(Olivier De Broqueville) #1

I have a context menu which calls a processSearch function when one of its items is selected:

browser.contextMenus.onClicked.addListener(processSearch);

Inside the processSearch function, I’ve got the following code:

browser.sidebarAction.isOpen({})
    .then((isOpen)=>{
        if (isOpen) browser.sidebarAction.close();
    })
    .catch((err)=>{
        if (logToConsole) console.error(err);
    });

I don’t understand why I’m getting the following error message because processSearch function is a user input handler:

Error: sidebarAction.close may only be called from a user input handler

Could this be a bug?

0 Likes

(Martin Giger) #2

The problem is that you check if the sidebar is open. You should just call close unconditionally from the handler directly and not defer it with a promise.

1 Like