1

Firefox's extensions leak memory and, with time, consume more and more CPU. This can be reset by disabling/enabling them. Is there a way to cycle all active extensions enabled status, without being forced to do it manually for each of them?

2
  • Firefox extensions do not leak memory. Instead of fighting the symptoms, try identifying the source. One or more of the extensions you have installed are the cause, and this can probably be fixed. Try doing a “binary” search for the culprits: Disable half of the extensions (then half of that etc) until you can single out extensions that cause the issue.
    – Daniel B
    Commented Nov 6, 2023 at 9:29
  • @DanielB Well, the FirefoxCP WebExtension (on a Mac), took more than 2 GB memory and even when I wasn't using Firefox, consumed 20-30 % CPU. After disabling/enabling all extensions, the memory was down to 120 MB and CPU around 1 %. I actually don't care about the culprit. I want/need all extensions I use and if that means that I once a week or so must disable/enable them, so be it.
    – d-b
    Commented Nov 6, 2023 at 11:34

1 Answer 1

0

Here is a very crude JavaScript solution:

function clickToggleButtons() {
  // Static XPath to count the number of nodes
  var staticXPath = '/html/body/div/div[2]/div/addon-list/section[1]/addon-card/div/div/div/div/moz-toggle';

  // Evaluate the static XPath expression to get a node list
  var staticXPathResult = document.evaluate(staticXPath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);

  // Count the number of nodes
  var numberOfNodes = staticXPathResult.snapshotLength;

  // Variable XPath to loop through nodes
  var baseXPath = '/html/body/div/div[2]/div/addon-list/section[1]/addon-card[%d]/div/div/div/div/moz-toggle';

  // Loop through each toggle button
  for (var i = 1; i <= numberOfNodes; i++) {
    // Construct the XPath for the current toggle button
    var currentXPath = baseXPath.replace('%d', i);

    // Select the toggle button using the constructed XPath
    var button = document.evaluate(currentXPath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;

    // Click the toggle button
    button.click();

    // Wait for 3 seconds before clicking it again
    setTimeout(function(currentButton) {
      return function() {
        currentButton.click();
      };
    }(button), 10000);
  }
}

// Call the function to start the process
clickToggleButtons();

Improvements are welcome!

Just open the web inspector, click Console, paste it and press enter. If you have a lot of extensions, it might take some time to reactivate them. It is not super stable so take note of all active extensions before running it, in case it fails to reactivate some of them so you can do it manually.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .