IE runs JavaScript only after pressing F12 - javascript

I have a strange problem in Internet Explorer with JavaScript. In every browser I did the test the JavaScript is enabled, but it seems to run only after I press the F12, running it in debug mode. And what is more confusing, after starting the IE debugger everything is working as suppose to.
Any ideas what it could be?

If you're calling:
console.log('...some text here...');
or any related method of console without having checked if window.console exists, the script will fail silently. Opening the console leads to window.console existing, which allows the script to continue execution.
Add "window.console && " before your calls to console:
window.console && console.log('works');

Related

console.log not working in non-icognito mode in Chrome

I have a problem with console.log in regular mode in Google Chrome. The same code logs correctly in Opera and in incognito mode in Chrome.
Here I've read recommendations to turn off Firebug extention but I don't have it.
Console.log messages not showing up in Chrome's javascript console?
I tried to turn off all extentions and then tested console.log (and alert) again with no success. in incognito mode it works fine, also levels filter is set to All levels (why is it disabled btw?) so nothing is hidden.
the same code
$("#turnOffAll").click(function(){
var filterId=$('#filterId').val();
console.log('clicked on filter'+filterId);
});
in regular mode in Chrome outputs nothing.
what can cause this behavior?
Deleting the cache worked for me. Open 3-dot-menu -> more tools -> delete browser data -> select cache.
You may not have enabled a correct level in your console:

javascript confirm prompt crashes Chrome extension on Mac

I have a Chrome extension with a few js confirm prompts like this:
return confirm("Are you sure you want to delete the order?");
On my windows PC it always works fine. On my Mac it always crashes my extension popup (and the confirm dialog never appears). Unless I step through it with Chrome developer tools--in which case it works fine 100% of the time and the confirm dialog displays and behaves correctly.
I have tried putting a try/catch around the confirm, which has no effect. The catch block is never entered.
I have tried running Chrome on the Mac from the command line, with switches to enable logging. I examined the log file after the crash. I saw lots of useless data in the log, but nothing relevant to my crash.
When I remove the confirm() it always works fine.
Instead of returning the result of the confirm directly, I tried setting var foo = confirm("foobar"); -- and returning foo -- no luck.
Any ideas?

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 ;)

debugger; in the Chrome console

Open a page in Chrome, enter the JavaScript console, and type debugger;. Immediately we hit a breakpoint at line 2 of the following code:
with ((window && window.console && window.console._commandLineAPI) || {}) {
debugger;
}
Can anyone make sense of this? Why the with statement? Why the breakpoint on debugger;?
Do you know what debugger is?
"Invokes any available debugging functionality. If no debugging functionality is available, this statement has no effect."
The code is basically saying if there is a console available with this browser and it has the feature "_commandLineAPI", start up the debugger.
The "with" statement basically is a catch all way to make sure there is not an error. In reality they should have just used an if.
Debug javascript Chrome doesn't need 'debugger' command.
Ctrl+Shift+J to Opens Developer Tools.
In the 'Sources' you can locate your js file or javascript in html.
Then click on line number to make a breakpoint on the left side.
Breakpoint will be triggered when it's executed.
You were in the command console that Chrome will try to excute any command line you input.

Firefox Web Console Disabled?

How come I get this message from Firefox Web Console
The Web Console logging API (console.log, console.info, console.warn, console.error) has been disabled by a script on this page
The same webpage can print messages in Chrome Console but not Firefox. I opened the same webpage in another computers' Firefox (don't know what version) Web Console can print messages. My Firefox version is the latest, 8.0.
This happens when the page itself defines a global variable called console, for example. If the page is browser-sniffing to decide whether to define it, the behavior could differ in different browsers.
In the case of Firefox it also happens when Firebug is installed and its console is enabled, since that overrides the default window.console.
I had the same exact error message, and once I removed firebug, it went away.
I'm not saying you should remove firebug, I love firebug, but that is most probably the source of the error for you as well. One more note, the error was still there even if firebug was turned off (disabled) for that particular page.
Here is a JavaScript workaround I used to restore console API after it was set to empty function by a script on the page (works in Firefox 46, tested in Firebug and in greasemonkey script):
function restoreConsole() {
var i = document.createElement('iframe');
i.style.display = 'none';
document.body.appendChild(i);
window.console = i.contentWindow.console;
i.parentNode.removeChild(i);
}
More info and credentials: Restoring console.log()
Right click over firebug console tab and uncheck "enabled" option (the first one).

Categories

Resources