0

Background info:

There are a lot of sites that load forever (especially those that depend on real-time JavaScript updates). Modern versions of Firefox (basically anything since 2015) use an extreme amount of CPU time (and overheat most laptops) while waiting for any tab to load.

Unending wait-for-load is evident by switching to an offending tab and checking the reload/cancel button. It will be stuck as an X (cancel) permanently until you click it and manually cancel.

What I'm asking for:

I'd like a configuration setting to impose a maximum load time limit across all tabs. Any tab that is loading for more than the specified limit will be automatically stopped (same as clicking the cancel button).

Due diligence (proof that I did my homework before asking):

I searched for anything that would do this and found a bunch of nonstarters:

Searching "firefox restrict maximum page load time" in Google turns up a bunch of performance tips aimed at faster page loads. Unfortunately that's of little use in a partially broken page that keeps loading forever.

This site (http://forums.mozillazine.org/viewtopic.php?f=38&t=2793647) said it can be done with an extension, although I don't see any extensions that do this.

Searching "firefox extension limit page load time" in Google only finds performance profiling and optimization, none of which are relevant.

  • 1
    I wrote an extension that does this. All I need to do is add a settings page to configure the timeout. Once I do that I can share it with you. – CoryCoolguy Sep 9 '19 at 14:29
  • 1
    Little update: currently waiting for Mozilla to approve the extension. That's it. – CoryCoolguy Sep 9 '19 at 21:07
  • Hey, if it's not too much trouble, could you mark my answer as the best answer? Or if there's an issue you have with it, could we discuss that? – CoryCoolguy Sep 17 '19 at 14:15
  • Thank you!!! 😊 – CoryCoolguy Sep 18 '19 at 3:40
2

While it seems nobody has created such an extension before, I was able to accomplish something in the form of a Firefox extension. The extension can be downloaded from here. But for the sake of writing a good answer, here's the important part:

background.js

function createAlarm(tabId) {
    function onError(error) {
        console.log(`Error: ${error}`);
    }

    function onGot(item) {
        var timeout = 15;
        if (item.timeout) {
            timeout = item.timeout;
        }
        browser.alarms.create(tabId + '', { delayInMinutes: timeout / 60 });
    }

    var getting = browser.storage.sync.get("timeout");
    getting.then(onGot, onError);
}

browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
    var id = tabId + '';
    if ("status" in changeInfo && changeInfo.status === "loading") {
        browser.alarms.get(id).then((alarm) => {
            if (alarm) {
                browser.alarms.clear(id).then((good) => {
                    createAlarm(id);
                });
            }
            else {
                createAlarm(id);
            }
        });
    }
});

browser.alarms.onAlarm.addListener((alarm) => {
    var tabId = parseInt(alarm.name);
    browser.tabs.get(tabId).then((tab) => {
        if (tab.status === "loading") {
            browser.tabs.executeScript(tabId, {
                code: "window.stop(); document.title = 'TIMED OUT | '+document.title;",
                allFrames: true,
                runAt: "document_start"
            });
        }
    });
});

Keep in mind that this extension does NOT discriminate. For instance, if you're purchasing something online and it takes a bit longer than expected, the extension WILL stop it.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.