javascript confirm prompt crashes Chrome extension on Mac - javascript

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?

Related

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

Failure installing the debug extension of your Crossrider Extension - Firefox

FF25.0, Fedora 18.
This just keeps going round in circles. The staging extension installs, and parts of it are active as the extension modifies a bit of the dom (I think even the background script is running too as the local storage is initialized). Not all of the extension works, such as the sidebar and other dom injection that should run on page load. But the debug mode page in crossrider fails to recognise the running extension.
I suspect this is due to a bug in my code but there appears to be no way to debug it. When I commented out the sidebar, it still showed briefly after another install, which makes me suspect a proxy/cache is getting in the way but adding an extra GET argument on the extension URL didn't help. I've tried adding debugger to extension.js. The console is empty. No errors are reported by firebug. The extension works fine in chrome, and I really don't want to go back to a blank extension and try adding bit by bit till it fails. There must be a simpler way such as making firefox just say, "here's your problem, right on line number X". Any ideas?
[EDIT]
After turning on some debug options, I've got errors in the console, but clicking on the offending file/line number just opens the "Source of:..." window. In google chrome I get the file in the debugger, can hit break points, refresh and catch the error as it happens. Better yet, how about a "break-on-exceptions" option that both works but also actually works.
[EDIT]
I finally got the Browser Debugger working. The first error is a NS_ERROR_XPC_BAD_OP_ON_WN_PROTO.
Well, to start actually getting messages you need to set some flags in "about:config" listed here: Setting_up_extension_development_environment
I'll copy a few...
javascript.options.showInConsole = true (this was already on for me)
browser.dom.window.dump.enabled = true
javascript.options.strict = true (there's also a debug version I turned on too)
devtools.chrome.enabled = true (nothing to do with google chrome)
devtools.debugger.remote-enabled = true (the important one, allowing Firefox->Web Developer->Browser Debugger, make sure to allow the remote debugger otherwise it undoes the config change)
devtools.errorconsole.enabled = true
extensions.logging.enabled = true
It looks like quite a few options have been removed too. This has at least got me started.
[EDIT]
This answer also mentions the "Web Developer->Browser Debugger" (which is currently blank - "no sources" - I have no idea) and "Web Developer->Browser Console" windows (just seems to have the same output as the in-window console).
Throw a giant try/catch around ALL your extension code. At least this allows the crossrider "staging" extension to install and be recognised.
Print the exception (I assume all the stupid about:config stuff has to be set for this to work)
appAPI.ready(function($) {
try {
...rest of extension code
}
catch (e)
{
console.log("#################", e);
}
}
Locate the error in the console, and click on the [object exception]. Note the line number (it won't be correct as other code is injected). Also note we've managed to print an exception and firefox failed to break on it. FFFFFFFFFFFFFFFFFFFF
Add some newlines approximately in the middle of the code.
Reload. Note the line number. If it's changed the error is after the newlines. If not the error is before.
Repeat from step 4 until the error is found.
Take a moment to reflect on the stupidity of this process. (this isn't exactly a comment directed at crossrider, more at the severe lack of simple web development tools and APIs currently available)

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

Windows Safari Freezes When Silverlight Calls a JavaScript window.alert/prompt

I have a Siverlight application, which needs to get something from the web page that hosts it. So I'm using HtmlPage.Window.Invoke("JS_OpenProject") in Silverlight.
Here is the JavaScript code:
function JS_OpenProject() {
// window.alert also crashes
window.alert("Here is a window.alert");
// window.prompt also crashes
//var result = window.prompt("Please input the id of the project to be opened:", "12345");
return result;
}
Safari freezes every time when the JavaScript method JS_OpenProject is called. If I remove the window.alert and window.prompt, it's fine.
On Windows, I tested my Silverlight application with JavaScript calling against IE, Chrome and Firefox, everything works fine, but just the Safari.
I have googled a lot, but no luck.
Please advise!
Thanks.
Peter
I had the same problem with FireFox and that seems to have been corrected now. The problem arises when Silverlight is run in windowsless mode.
If you don't need it turn it off, it will run even faster.

IE runs JavaScript only after pressing F12

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

Categories

Resources