How can I change the content of a sidebar from a background script?

I’m trying to update the content of a sidebar but I cannot set it’s content from a background script. How can I do this? Is this possible?

Thank you

https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/sidebarAction/setPanel

Aaaaa… I misunderstood the API. I thought that I can only set an existing hardcoded file but I can set any dom element I want in the setPanel fucntion, right? Will try that when I will get home. Thank you again for your help @freaktechnik :slight_smile:

I think you can also use blob and data URIs, yes. Else you’ll have to use a blank html file of your extension with a script that inserts whatever you want.

 browser.sidebarAction.setPanel({panel: 'data:text/html,lots of text...<p><a name%3D"bottom">bottom</a>?arg=val'});

I get this :frowning:

Error: Access denied for URL data:text/html,lots of text...<p><a name%3D"bottom">bottom</a>?arg=val

also… background js

    browser.runtime.sendMessage({"url": 'value'});

sidebar.html

 <script>
   function handleMessage(request, sender, sendResponse) {
     document.getElementById("myElement").innerHTML = 'test';
   }

   browser.runtime.onMessage.addListener(handleMessage);

 </script>
  </head>

   <body>
 <div id="myElement">This is an awesome certificate info!</div>

Error: Could not establish connection. Receiving end does not exist.

That should definitely work. Though I’d suggest doing communication the other way around and sending a response from the background script.

I have a context menu that triggers this… the context menu item and listeners are in the background script.

I made my addon public! Uuuhuuu! Still uses an ugly alert as an UI. If you have a better proposal I’m all ears :smiley: