WebExt API to stop a loading tab?

I am working on an addon that goes thru the tab list and one by one loads discarded tabs (to load the favico) and then discards them. The issue I am having is that obviously some tabs take a long time or never completely load and their tab.status never changes to “complete”. Because of this I want to do a timeout (no problem), but if the timeout triggers and the tab is then discarded, tree style tab still shows the loading favico rather than the sites actual favico.

Is there a way to tell the tab to stop loading from an addon?

Desired workflow:

  • Check if tab is discarded “if (tab.discarded)”
  • If discarded: issue “browser.tabs.reload(tab id)”
  • Wait for “tab.status = complete” OR 10 second timeout
  • If “complete”, issue “discard” … else if timeout, issue “Stop loading” then “discard”

Is there something like “browser.tabs.stop-loading(tab id)” that emulates the user clicking on the “stop loading” X?

Maybe this will work:

        browser.tabs.executeScript(tab.id, {
            code: "window.stop();",
            allFrames: true,
            runAt: "document_start"
        });

You’ll need the ‘Access your data for all websites’ permission, though.

1 Like