Setting contentURL on panel breaks emit

Hi,

this is my first post here.

I have a test-case where I make a panel connected to a toggleButton. In the panel there is a button which emits a signal to ask to addon to get the site url (from tabs module). The url is then communicated back with with an emit to the panel for display.
The problem is that when I switch the contentURL of the panel, the ‘set-url’ emit stops working. I know it doesn’t make sense to switch the contentURL here, but this is just a test-case. Maybe this is a bug in panel? Note that ‘get-url’ keeps firing when I push the button.

panel.port.on("get-url", function() {
    console.log("get-url handler");
    panel.contentURL = self.data.url("index.html");
    panel.port.emit("set-url", getCurrentURL());
});

Can you show code before and after the contentURL change. It would help to see both sides of the code, port and main.

I worked around the problem by putting all my html in one file and just setting div’s to hide/show. I still don’t understand why switching the contentURL does not work though.

This is the add-on code (mostly):

function togglePanel(state) {
    if (state.checked) {
    panel.show({position: button})
    panel.contentURL = self.data.url("index.html");
    panel.port.emit("init");
    } else {
    panel.hide();
    }
}

panel.port.on("get-url", function() {
    console.log("get-url handler");
    panel.contentURL = self.data.url("index.html");
    panel.port.emit("set-url", getCurrentURL());
});

function getCurrentURL() {
    return tabs.activeTab.url;
}

This is the panel-code:

self.port.on("init", function() {
    var btn = document.getElementById("url-btn");
    btn.onclick = function() {
    console.log("btn click handler")
    self.port.emit("get-url");
    }
})

self.port.on("set-url", function(url) {
    console.log("set-url handler");
    var box = document.getElementById("box");
    box.innerHTML = url;
});

The output in my console when pressing the ‘get url button’ is then

console.log: panelcontentswitch: btn click handler
console.log: panelcontentswitch: get-url handler
console.log: panelcontentswitch: btn click handler
console.log: panelcontentswitch: get-url handler

As you can see, the ‘set-url’-handler is not called. When I comment out “panel.contentURL = self.data.url(“index.html”);” in the ‘get-url’-handler, everything works fine.

I asked on the IRC channels, this is what someone told me:

07:32:30 <The_8472> setting the url navigates the iframe, meaning a new script will be loaded
07:32:41 <> maksik (maximzhilya@moz-hjkm2l.ca.comcast.net) has joined #jetpack
07:32:45 <The_8472> you have to wait for the page/script load before sending the next message