Search code examples
google-chromegoogle-chrome-extensionsidebar

How can I specify a sidebar in Chrome extension?


I'm trying to add a sidebar (experimental) to my extension.

I've enabled the "Experimental Extension APIs" in Chrome.

When I invoke:

chrome.experimental.sidebar.show(cTab);

method, (where cTab is current tab) I get an error:

Error during experimental.sidebar.show: This extension has no sidebar specified.

When I invoke:

chrome.experimental.sidebar.getState(cTab, function (state) { alert(state); });

I get "undefined" in the alert box.

I read the specs of chrome.experimental.sidebar and I have no clue how to add a sidebar to Chrome.

How can I specify a sidebar for my extension? Please help.


Solution

  • First declare sidebar in your manifest:

    {
        ...
        "sidebar": {},
        ...
    }
    

    Then to display sidebar.html in a current tab:

    chrome.experimental.sidebar.show();
    chrome.experimental.sidebar.expand();
    chrome.experimental.sidebar.navigate({path: "sidebar.html"});
    

    Here is example extension.