I want wrote extension, that will open sidebar (with bookmarks) on New Tab, and close it on other tabs.
I make background script with next content:
browser.tabs.onActivated.addListener(function(tab){
if(tab.url=="about:newtab")
browser.sidebarAction.open()
else
browser.sidebarAction.close()
})
And I get next error in console: browser.sidebarAction is undefined
Also I can see here that such actions “can only be called from inside the handler for a user action.” Clicking the extension’s browser action or page action.
And I want ensure whether tabs.onActivated event is a User action?
And if not, is there any ways or suggestions to go around this limitation?
First, to paste code here, make sure to place ``` on the line before and after the code to enable code highlight
.
Now, if the “browser.sidebarAction
” is undefined, then you have probably forgot to put it in your manifest file (see if you have there sidebar_action
key).
But still, I don’t think you will be able to go around the “user action” restriction. As you can see, the list of user actions is short and strict:
Clicking the extension's browser action or page action.
Selecting a context menu item defined by the extension.
Activating a keyboard shortcut defined by the extension.
Clicking a button in a page bundled with the extension.
Maybe if you register “Ctrl + T” hotkey you would be able to open it when user opens the new tab using the hotkey. But closing is still a problem. I can’t think of any workaround…
I want to open standard firefox’s sidebar (with bookmarks, journal etc), not my own custom sidebar.
I also try to call sidebarAction.open()
from browser_action’s popup menu:
document.getElementById('button').onclick = function(){
browser.sidebarAction.open()
}
and get the same error: browser.sidebarAction is undefined
Is there any way to open standard firefox’s sidebar (with bookmarks, journal etc)?
No, you can only open your own extension’s sidebar.