12

We have a web application which runs in a kiosk mode Firefox, using the RKiosk extension to achieve this. We suspect that we have a very rare error in the system which yields in a JavaScript error. However because we can't access the JavaScript console we can't examine the log.

I'm searching for an option to make Firefox log all JavaScript console messages into a file regardless of the tab and page opened. I can't seem to find any extension for this. I'm already using log4javascript which sends errors back to the server, but it seems that our application crashes in a way that it skips the logging altogether.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
NagyI
  • 5,907
  • 8
  • 55
  • 83
  • You could use the file api and write to the local file system. – epascarello Oct 10 '13 at 14:29
  • Cab you target indexedDb with your logger instead of the server? – Mister Epic Oct 10 '13 at 14:29
  • 1
    have you tried http://www.softwareishard.com/blog/consoleexport/ yet? – Zathrus Writer Oct 10 '13 at 14:35
  • Not exactly what you're looking for, just an idea that I tried out before: use `window.onerror` and save all errors to localStorage. – user123444555621 Oct 10 '13 at 14:37
  • I'm already using log4javascript to send errors back to the server. So the problem is that i don't know how any error escapes logging this way. That's why i like to make Firefox log all errors into a file aswell. – NagyI Oct 10 '13 at 14:53
  • Zathrus: i can't access Firebug because in kiosk mode everything is disabled. I can't leave Firefox with the browser controls available for the strangers who are using the public service. – NagyI Oct 10 '13 at 14:58
  • 2
    @NagyI It sounds like you need a browser plugin which will take care of this. I tried searching for one but couldn't find any. Sounds like an interesting weekend project. – Munim Oct 15 '13 at 08:48
  • what server side language are you using? It's possible I or somebody else could make something like log4javascript that works for you situation – markasoftware Oct 21 '13 at 02:31

7 Answers7

4

Writing to a file sounds like a tedious task to me. It requires privileges that browser code doesn't normally have and you'd have to negotiate with an add-on you'd have to write in order to access file I/O.

From what I understand your issue is

I'd like to make Firefox log all errors

There are several approaches we can do to tackle this

First approach - log everything to localStorage too:

Now, rather than writing to an actual file, you can write to localStorage or IndexedDB instead.

localStorage["myApplog"] = localStorage["myApplog"] || "";
var oldLog = console.log;
console.log = function(){
    oldLog.apply(console,arguments); // use the old console log
    var message =  "\n "+(new Date).toISOString() + " :: "+
                   Array.prototype.join.call(arguments," , "); // the arguments
    localStorage["myApplog"] += message; 
}

This is rather dirty and rather slow, but it should get the job done and you can access the log later in local storage. LocalStorage has a ~5MB limit if I recall correctly which I think is enough if you don't go crazy with logging. You can also run it selectively.

Second approach - log only errors

This is similar to what Pumbaa80 suggested. You can simply override window.onerror and only log errors.

// put an empty string in loggedWinErrors first
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 drastic approach - use a VM.

This is the most powerful version, but it provides the most problematic user experience. You run the kiosk in a virtual machine, you detect an uncaught exception - when you do you freeze the machine and save its state, and run a backup VM instead. I've only had to do this when tackling the most fearsome errors and it's not pretty. Unless you really want the whole captured state - don't do this.

Really, do the extension before this - this is tedious but it gets very solid results.


In conclusion, I think the first approach or even just the second one are more than enough for what you need. localStorage is an abstracted storage that web pages get for saving state without security issues. If that's not big enough we can talk about an IndexedDB solution.

It all really depends on the use case you have.

Benjamin Gruenbaum
  • 270,886
  • 87
  • 504
  • 504
  • You say browser code doesn't have a privilege to use File I/O. Is this the case with browser extensions? I'm looking for something more universal than putting the weight lifting into my webapp. Install something into Firefox which transparently logs everything in the background. – NagyI Oct 15 '13 at 09:31
  • Browser extensions _do_ have access to File I/O. You can look at the tutorial I linked to at the end of the first two lines - it contains lots of code samples that can help you. If you want to abstract it from your app you can just override postMessage and then post a message to a worker taking care of it. Take note I/O is pretty expensive regardless. – Benjamin Gruenbaum Oct 15 '13 at 09:42
  • Thanks. I'll experiment with this soon. – NagyI Oct 15 '13 at 10:22
  • @NagyI Please provide feedback. – Benjamin Gruenbaum Oct 23 '13 at 10:50
  • Sorry i didn't had time to experiment and i was offline for several days so you got the bounty automatically. Thanks for all the mentioned solutions i think you deserve the bounty, although vbail's solution is the closest to what i'm looking for so i accepted that. – NagyI Oct 23 '13 at 16:42
3

You can use XULRunner...a Mozilla runtime environment for XUL applications. It uses Gecko like Firefox and:

  1. You can access the file system or using the SQLite database to store logs.
  2. You can render your kiosk in fullscreen mode without using extensions.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
StaleMartyr
  • 778
  • 5
  • 18
  • I never thought about using XULRunner for this but it seems like a good idea. I'll check this out if i can. – NagyI Oct 23 '13 at 16:44
2

Have you tried jserrorcollector? We are using it and it works fine (only in Firefox). It's only for Java.

// Initialize
FirefoxProfile ffProfile = null;
ffProfile = new FirefoxProfile();
JavaScriptError.addExtension(ffProfile);

 // Get the errors
List<JavaScriptError> jsErrors = JavaScriptError.readErrors(webDriver);

More information: https://github.com/mguillem/JSErrorCollector

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
vbail
  • 364
  • 3
  • 14
  • Wow, interesting solution. I definietly give this a try. This way i can package my whole app using an external Java boostrapp app which launches the webserver and Firefox aswell. This is the closest thing to what i want so i accept this answer. – NagyI Oct 23 '13 at 16:46
1

Have you considered remote logging?

I commonly assign window.onerror to do send a request to a webserver storing the details of the error remotely. You could do the same with console.log if you preferred.

Murph
  • 1,479
  • 2
  • 13
  • 26
  • http://stackoverflow.com/questions/19298420/log-javascript-console-into-a-log-file-with-firefox/19377514#comment28579422_19298420 OP is already doing remote logging. – Benjamin Gruenbaum Oct 22 '13 at 09:28
1

Try the following console export. It is a plugin for Firebug of Firefox. It's quite handy.

http://www.softwareishard.com/blog/consoleexport/

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Alan Dong
  • 3,981
  • 38
  • 35
0

If you are able/willing to switch from Firefox to Chrome or Opera you would be able to use the Sandboxed Filesystem API to write a local file. See:

Start in kiosk mode using chrome.exe --kiosk <url>

You would then want to disable Alt-F4 and Ctrl-Alt-Del which on Windows can be done with several third-party tools like Auto Hotkey (Disable Ctrl-Alt-Del Script).

SpliFF
  • 38,186
  • 16
  • 91
  • 120
0

You could use a remote logging script like Qbaka. It catches every JS error and sends it to the Qbaka server. There you can login and see all JS errors. Qbaka stores the exact error message, the script, line number, stack trace and the used browser for each error message.

Reeno
  • 5,720
  • 11
  • 37
  • 50