var timeout = prompt ("Enter the number of minutes to restart:", "1440"); if (timeout) { window.setTimeout ("Application.restart ();", timeout * 60 * 1000); }
var timeout = 1440; // minutes window.setTimeout ("Application.restart ();", timeout * 60 * 1000);
timeout
parameter will begin. Again, the default is to restart once a day, but the user can replace the number 1440 with any other (do not accidentally enter too small an interval (fraction), otherwise you will have to deal with the consequences in safe mode).idleLimit
parameter (set in minutes), the browser will restart.var idleLimit = 60; // minutes var idleService = Components.classes ["@ mozilla.org/widget/idleservice;1"] .getService (Components.interfaces.nsIIdleService); window.setInterval ( function () { if (idleService.idleTime / 60000> idleLimit) { Application.restart (); } }, 60,000 );
about:memory
page appeared. Analysis of its code leads to the chrome://global/content/aboutMemory.js
file, which uses several undocumented interfaces again. With their help, you can take a chance on such a code (the function goes through the available types of memory, and if at least one of them exceeds the set limit (specified in megabytes), the browser will restart):var memoryLimit = 200; // megabytes var enumeratedReporters = Components.classes ["@ mozilla.org/memory-reporter-manager;1"] .getService (Components.interfaces.nsIMemoryReporterManager) .enumerateReporters (); while (enumeratedReporters.hasMoreElements ()) { if ( enumeratedReporters.getNext () .QueryInterface (Components.interfaces.nsIMemoryReporter) .memoryUsed / 1000000 > memoryLimit ) { Application.restart (); } }
However, it is not known how the interfaces used depend on the operating systems (there are mentions in the network thatabout:memory
does not work in Linux). It is also unclear in which version of Firefox these interfaces appeared. Therefore, I would be grateful to the readers if they could test the following code and unsubscribe in the comments about what it issues on different OCs and different versions of Firefox (try not to repeat the configurations that have already been unsubscribed):try { var enumeratedReporters = Components.classes ["@ mozilla.org/memory-reporter-manager;1"] .getService (Components.interfaces.nsIMemoryReporterManager) .enumerateReporters (); var report = ""; while (enumeratedReporters.hasMoreElements ()) { var memoryReporter = enumeratedReporters.getNext () .QueryInterface (Components.interfaces.nsIMemoryReporter); report + = memoryReporter.path + ": \ t" + memoryReporter.memoryUsed / 1000000 + "\ n"; } alert (report || "Memory information not available."); } catch (error) {alert (error)}
var idleLimit = 60; // minutes var memoryLimit = 200; // megabytes var idleService = Components.classes ["@ mozilla.org/widget/idleservice;1"] .getService (Components.interfaces.nsIIdleService); var reporterManager = Components.classes ["@ mozilla.org/memory-reporter-manager;1"] .getService (Components.interfaces.nsIMemoryReporterManager); window.setInterval ( function () { if (idleService.idleTime / 60000> idleLimit) { var enumeratedReporters = reporterManager.enumerateReporters (); while (enumeratedReporters.hasMoreElements ()) { if ( enumeratedReporters.getNext () .QueryInterface (Components.interfaces.nsIMemoryReporter) .memoryUsed / 1000000 > memoryLimit ) { Application.restart (); } } } }, 60,000 );
Source: https://habr.com/ru/post/94550/
All Articles