I am migrating my extension from the SDK to WebExtensions, and I can not find the way of communicating between a background script and the sidebar. The idea is to pass the text the user highlights and some extra info when he clicks in a context menu. I need to copy this selection in the "selected-text" input, but I can not manipulate the DOM of the sidebar from the script...: (
browser.contextMenus.create({
id: "save-highlighted-data",
title: browser.i18n.getMessage("save-data"),
contexts: ["all"],
onclick: function(info,tab){
//I got the highlighted data
console.log("Selected text: " + info.selectionText);
browser.sidebarAction.setPanel({
panel: browser.extension.getURL("/sidebar/annotation.html")
}).then(function(){
//In this context, "this" = the chrome window. But I can not change the document
// of the sidebar
//console.log("window", this.document.querySelector("#selected-text"));
});
},
command: "_execute_sidebar_action" //This toggles the sidebar
});
Any idea? I checked the sidebar examples at the GitHub repo, but they just open a sidebar with not more communication that the sidebar toggle action ("_execute_sidebar_action"
)