When it comes to writing to a file, I find the process to be quite burdensome. Browser code usually lacks the necessary privileges for such a task, requiring you to work with an add-on that you must create in order to access file I/O.
It seems like your main concern is
Making Firefox log all errors
There are various approaches we can take to address this issue
First option - save everything to localStorage as well:
Instead of writing to an actual file, you have the option to write to localStorage
or IndexedDB
as an alternative.
localStorage["myApplog"] = localStorage["myApplog"] || "";
var oldLog = console.log;
console.log = function(){
oldLog.apply(console,arguments); // utilize the old console log
var message = "\n "+(new Date).toISOString() + " :: "+
Array.prototype.join.call(arguments," , "); // the arguments
localStorage["myApplog"] += message;
}
This method may not be the cleanest or the fastest, but it should serve the purpose. You can access the log later in local storage. LocalStorage generally has a ~5MB limit which should be sufficient unless you excessively log. You can also choose to run it selectively.
Second option - log only errors
This approach is similar to the suggestion by Pumbaa80. You can simply override window.onerror
and log only errors.
// initialize loggedWinErrors with an empty string
var oldError = window.onerror || function(){};
window.onerror = function(err,url,lineNumber){
oldError.call(this,err,url,lineNumber);
var err ="\n Error: (file: " + url+", error: "+err+", lineNumber: "+lineNumber+")");
localStorage["loggedWinErrors"] += err;
}
Third and extreme option - utilize a VM.
This approach is the most powerful but results in a problematic user experience. By running the kiosk in a virtual machine, you can detect uncaught exceptions, freeze the machine, save its state, and switch to a backup VM. This method is typically reserved for dealing with severe errors and is not recommended unless absolutely necessary.
Prioritize creating an extension before resorting to this method - although tedious, it yields solid outcomes.
To sum up, I believe the first or second approach should suffice for your requirements. localStorage
serves as a secure storage option for web pages to store data without security concerns. If additional storage capacity is needed, consider an IndexedDB solution.
The most suitable approach depends on the specific use case.