clear up GM_log from error console - firefox

Is there a way to clear up GM_log messages from error console from userscripts on a certain event?
I don't want to clear up manually. On trigger of certain event, want to clear up the old log from the error console and show up the new log.

You cannot clear the error console. If you could, evil websites could clear it too and erase the record of their misdeeds.
You should no longer use GM_Log() anyway. Use Firebug and the excellent console logging functions it provides.
Then you can use console.clear().
Note, to avoid conflicts with Firefox's newish console functions, and to ensure that the output appears in Firebug's console, you may need to prefix the calls with unsafeWindow.
So your script could do something like this:
unsafeWindow.console.clear ();
unsafeWindow.console.time ('ScriptRun');
unsafeWindow.console.log ("Script start." );
unsafeWindow.console.timeEnd ('ScriptRun');
Which would look like this in the Firebug console:
-- with all the preceding cruft erased. (Anything the webpage does after the clear() call will still appear though.)

Related

Firefox add-on devtools logs don't show object keys/values

I'm currently developing a Firefox add-on and I noticed some logging issues in the add-on devtools (for the background script) page. Whenever I'm trying to console.log some object, I don't see any keys or values of this object in the console. There's also no way to "expand" the object like I can in the "regular" (not for an add-on) Firefox browser console.
So, if I e.g. open the add-on devtools and type console.log({ test: "test" }), I only do get "Object { }" as an output:
If I try to log an error I do get a similar result (I can e.g. still log err.message):
try {
throw new Error("");
} catch (err) {
console.log(err);
}
Since I'm currently developing the add-on locally, I'm using web-ext to launch and watch the add-on. web-ext run is essentially launching Firefox without any profile which I thought may explain the difference compared to a regular Firefox browser console.
However, even if I load the add-on in my normal Firefox profile (load temporary add-on), I do see the same behavior for any add-on devtools console.
Is there any setting in the Firefox (add-on) console (or in my preferences) that I can use to log the whole object like it does in the normal Firefox console, e.g. if I open devtools for a regular webpage:
It's hard to tell what's going on without seeing the relevant code for your Firefox add-on, but I have a hunch that this is happening because of reference changes in your script.
In Javascript, an object is actually a reference to a location in memory. So when you run console.log(obj), and that object is modified before you access the console, then it may show up as empty (i.e. because the value being referenced has changed).
I would make sure that the object that you are trying to log is not modified after you log it. If there are any other objects based on the one that you are trying to log, changes to them may also cause your initial object to change as well.
You can try JSON encoding to get around this for logging purposes:
console.log(JSON.parse(JSON.stringify(obj)));
If that's not the issue, then perhaps there's some weird async behavior going on. In that case, you can try logging the object at several other points in your code to see exactly where this behavior starts.

View output of previous commands

Is there a way to view all the past logs such as API responses, warnings etc that displayed on the shell after closing it? Typing "history" will just show the history of commands. I need to see the past logs / everything else
No, that's not possible. By default, only the commands are logged.

How can I log javascript errors with Poltergeist/Capybara/Rspec?

I'm using Rspec/Capybara with Poltergeist as a driver to write tests for some large web applications.
My issue is that I would like to record the messages that appear on the console, but so far I've been unable to do so.
I am aware of the options js_errors and phantomjs_logger, but I have had some issues with them:
if I set js_errors: false, the file I specify in phantomjs_logger stays empty;
if I set js_errors: true, console.log messages are logged in the file specified in phantomjs_logger, but then almost all my specs fail because of
javascript errors that may not even be relevant to the navigation example I'm testing.
Any idea on how I can save the console messages while not breaking specs on every js error?
CLARIFICATION:
I have no control over the development, my task is to check the stability of the whole stack of the applications in the various environments, accessing from the front-end, so clearing out all the javascript errors is out of the question. The specs I'm writing are also supposed to ignore javascript errors if they don't impair the usage of the interface.
You can't. The PhantomJS client catches javascript error messages and adds them to an array. Then when a command completes, if js_errors == true, that array is checked and if not empty the javascript errors are returned and trigger an error in the test. There is no other API in poltergeist for accessing those errors. It sounds like you need to have a discussion with your manager about the wisdom of just ignoring JS errors if they apparently don't impair usage - it's a potentially dangerous development practice

Prevent browser-sync log data in firebug console

I often use gulp and its plugin browser-sync.
Every time i open firebug console tab, i see its full of logs like :
GET http://localhost:3000/browser-sync/socket.io/?EIO=3&transport=polling&t=1457523519574-0 200 OK ۳ms browser...11.1.js (line 2)
I can use clear button but logs are interminable! they will appear twice.is there any persistent way to ride of these(browser-sync) logs?
Yes, there is. Just uncheck the option Show XMLHttpRequests within the Console panel's options menu.
Though note that this will disable the logging for all XMLHttpRequests, (aka AJAX requests).
There is currently no way to filter out specific logs. There are already two enhancements requests for that: issue 4507 and issue 6835 targetting Firebug 2, but as Firebug 3 will be built upon the DevTools, it is probably wiser to follow the DevTools related requests. The closest one to your issue is bug 905978 to filter out messages for blackboxed sources, but I've also filed bug 1102797 some time ago for allowing to blackbox sources from within the Console panel and bug 1255311 right now for ignoring specific log messages.

Displaying Error Page in WP7 app

Just want to check I have not missed anything obvious. There is no way to Navigate the user to a "ooops something bad has happened" page from the UnhandledException handler is there?
What is everyone else doing
I know I can "handle" the error and popup up messagebox but I would prefer a whole page offering them the oppurtunity to file a bug report.
The samples I have seen simply set the RootFrame directly but I have seen that just makes for a messy UI with what looks like a Page displayed on top of another page
TIA
Pat
If you get an UnhandledException it occurs while your applicaiton is about to be shut down. The best you can do in this situation is warn the user that something went wrong (using a messagebox or similar) but be prepared that this may not be displayed to the user for long, depending on the actual exception.
Rather than try and continue executing application functionality when an unhandled exception occurs, simply save the details of the exception. Then, when the application is next started, display a message to the user to indicate that "the last time that app ran there was a problem". You can also use this opportunity to send exception details to yourself/ your web reporting service so you can analyse the issues and fix/prevent them in a future version.
You can call RootFrame.Navigate(your errorPage) to navigate to your custom error page in the UnhandledException handler.
Basically, using a custom MessageBox to show a nice easy-going error info and providing an button to send bug report is very common. And this article is MSDN pointed out that errorinfo not be a separate page in best practice.

Resources