tabs.executeScript does not work with containered tabs

Is there a way to get tabs.executeScript working on containered tabs when using with Firefox multi-account container add-on?

For example, the following code would work if opened tab has no-container but not working if opened tab is in a container.

browser.tabs.create({url: url}, (tab) => {
            browser.tabs.executeScript(tab.id, {
                code: `console.log('abc');`
            });
    });

That’s most likely not a problem, at least I don’t see why it shouldn’t work.

But there is a potential issue, if you try to open a page that’s assigned to a container, the Firefox Multi-Account Container addon will CLOSE the tab and reopen a new one.

This is happening because Firefox currently doesn’t support switching tab to a different context, so new one is required.

So in your code, the “tab” you are getting is likely closed and the executeScript or any API call will fail.

Use some console logs or debugging to verify that, then we can start thinking about a solution, which may not be pretty :upside_down_face:.

Thanks for pointing me to the right direction.

Yes, the tab was closed and reopened so
immediate workaround I can think of now is to set some timeout and get active tab instead.

1 Like