console.log doesn't print the message to the firebug console? - javascript

I am facing this weird problem. The WebApp I'm debugging right now, is invoking the javascript console.log/console.log/error/debug/etc., the Firebug console however, doesn't print them at all.
This application uses Dojo/Dijit toolkit. Not sure if there is anything special about it
It doesn't appear to be a problem with the Browser, I tried another simple web-page with a console.debug call, and the message appears on the console as expected.
Please advise about what should I look for. I have also tried Chrome/IE.
Thanks in Advance/

console is not write protected, it can be replaced with anything. You could try
alert(console.log.toString());
to find out what console.log really is
Edit:
A better method would be
var originalConsole = console;
// now include your library
// ...
originalConsole.log(console.log);
In Firebug, clicking on the function takes you directly to its definition.

did you try window.console.log()? Maybe you are not in window scope

In case like this do not forget to check if "Logging" is enabled or active at your console of browser.

Just to update this question -:
Ensure that firebug is Enabled - - > On for all Web Pages.
Reload the application.
Then in the firebug panel - - > Console - - > All.
All the console.log messages will appear.

Related

Console doesn't log js errors from content script

I know that to debug content script use normal web developer tools (https://developer.mozilla.org/en/docs/Mozilla/Add-ons/WebExtensions/Debugging#Debugging_content_scripts), and this works perfect. debugger keyword works as intended.
But in this exact situation things get broken:
addon.id = "123-568-485"; // I never define `addon` before this line, so this cause: ReferenceError: "addon is not defined". We aren't aware of this mistake.
// Some more code
// Some more code
// Some more code
// Some more code
debugger; // Here we want to stop execution and inspect, some other stuff. Remember that we aren't aware of earlier mistake.
What we would expect, that in console error about Reference error will appear, but it doesn't. Console get silent, and we don't know why our debugger keyword doesn't work.
This kind of silent error, happened to me when I misspell variable name. In result couldn't figure out what's wrong.
The errors in the content script are not reported in the tab's Web Console due to Firefox bug 1410932, which is not fixed (as of Firefox 79, released on 2020-07-28).
I listed possible workarounds in another answer:
use try..catch with logging,
check the Browser Console (which does show errors from the content script)
use the Debugger's "pause on exceptions" option.
Content scripts are executed in webpage, So as you know to see it's output you should open up console menu in that specific web page (ctrl+shift+e then go to console).
But if something is wrong with content script and cause it to throw exception, The error log would be shown in debug area of your extension in: about:debugging
I think the reason is content scripts are treated like extra frame for webpage and their error is shown there.

How to fix IE9 issue with f12?

I need to be able to run my angularjs app in IE9 but this currently only works with devtools open(F12). From what I am aware is that console.log can cause this but this is stripped out in the app , I am using gulp.stripDebug. What can be another cause or is this a IE9 bug?
Is there a way of debugging/tracking js code without having to open the devtools at the same time?
If console is not defined, calling .log() will break javascript execution. An easy way to overcome this is to check if it exists and create a dummy object if it does not. If you load the page without developer console and open the console afterwards, logging won't work though.
if (!window.console) {
window.console = { log : function () {} };
}
You could make the function alert the debug message, but that would probably annoy more than it would benefit you ;)

Facebook like button in site that uses post message spams console

I have a site that uses a lot of postMessage communication between iframes. Putting a Facebook like button in my site causes my debug console to get spammed with messages like
Received message of type object from [domain], expected a string.
This makes development very difficult. Is there any way to prevent this extra logging from occurring? I am new to using facebooks apis so I'm hoping I'm just missing something simple. They can't possibly assume that no one besides them will ever use postmessage.
Thanks!
Actually, disabling console.log is a horrible answer. What if we want to use console.log, but just want to stop the spamming error message? What is causing it? How do we actually fix it?
Actually that's not an extra logging. It's from the Facebook SDK. Simply you can uglify the sdk for removing all console from the library.
1.Download the sdk. https://connect.facebook.net/en_US/sdk.js
2.Uglify it for removing console logging (production version.)
https://github.com/mishoo/UglifyJS
3.Use it in your site.
Another link which may help you:
http://elijahmanor.com/grunt-away-those-pesky-console-log-statements/
You could simply "unset" the console.log function, by doing something like:
console.log = function(){}
Save it in another variable first, for example:
var originalLog = console.log;
Now when the Facebook API tries to use the log function nothing will happen. If you need to use the log function, just enable it first by setting it back to your saved originalLog variable and unset it when you are done using it. Unhandled errors will still show up in your console, regardless of what you have done to the log function.
In my case this was caused by the FVD Video Downloader extension, so maybe you should disable all browser extensions and see if that solves the issue, then enable them back one by one to find the culprit.

How to write all javascript/Jquery exceptions to one text file?

I want to log/write all javascript errors to one text file when ever an error happens in my JavaScript functions or jQuery plugins.
For eg. PHP page call fails, undefined var.. etc. like errors happens I need to write it on a text file.
How can I do that. Please help me.
You can use console.log for logging after installing firebug
https://getfirebug.com/
Dependes on witch browser you are using:
> Firefox? - Look at firebug http://getfirebug.com/
> Chorme? - Right Click > Inspect element
> Safari? - Preferences > Advanced > Show develop menu in menu bar
> IE? - To complicated download another browser. :)
And then use console.log(...);
Whenever I get errors in javascript I make a call to my "LogError" function which passes the error data to a web service which can then log it on the server or email it off or whatever you need.

misspelling javascript function alert to alerler('hell'); and firebug doesn't report an error?

misspelling javascript function alert to alerler('hell'); and firebug doesn't report an error.
Why is that? It is enabled for localhost (or my site).
I'm guessing you mean you have a <script> that has a call to alerler somewhere, right? Well, Firebug only catches errors for code that gets run. ;) So if the code with the misspelled function isn't actually run after the page loads, Firebug won't catch the error. This is the only reason I can think of as to why Firebug didn't catch your error.
Works On My MachineTM, or should I say Doesn't Work On My MachineTM
>>> alerler('test');
ReferenceError: alerler is not defined
Maybe your FireFox Error Console (Ctrl+Shift+J) could help you on that
Firebug has some weird quirks sometimes like if you setup a debugger; and refresh the page without stopping the debugger, firebug well no longer work properly. Sometimes you get lucky and don't have to restart the browser.
This is very unlikely, could you have defined a function?
function alerler(text) {
// this is a possibility!
}
Though, I would say musicfreak has the most probable reason.

Categories

Resources