error appears out of blue in console - javascript

I am receiving an error in my error console which states: arguments array passed to Function.prototype.apply is too large and the file it is in is: resource://ct2504091/BackStage.jsm. Does anyone know why this error suddenly appears out of the complete blue?
Below is the code from the view source of where the error is appearing in:
var postBytes = stream.readByteArray(stream.available());
poststr = String.fromCharCode.apply(null, postBytes);

A Google search for "javascript BackStage.jsm" reveals: You seem to have installed a "Bibirmer for Firefox Plugin" that interfers with you code. Try uninstalling it.

Related

How to output a message in Googles Blockly?

I'm having a bit of fun on https://blockly-games.appspot.com and have got to the last level where you can write full blown javascript (new Date().getTime(); is very handy).
Despite having the console open in Chrome (ctrl-shift-j) I can't seem to write anything to it with console.log("test"); from within the game. When I do I see:
// Starting battle with 2 players. compressed.js:420
// [Player] throws an error: Unknown identifier: console compressed.js:423
// undefined compressed.js:423
// [Player] dies. compressed.js:416
Yet if I type console.log("hmm"); in the console I properly see:
// console.log("hmm");
// hmm VM1038:2
// undefined
Same story if I try to use alert("test").
I want to debug, but the only forms of output I've found are manipulating the duck and throwing Unknown identifiers. Is there any way out of this sandbox?
Update: How do I print debug messages in the Google Chrome JavaScript Console? has some ideas for restoring console but they don't seem to work in this case.
Update: just to be clear this is what chrome looks like when experiencing this error.
Found a kludgey workaround:
throw "\nYour message here.";
Displays:
// [Player] throws an error: Unknown identifier: compressed.js:423
// Your message here.
// undefined compressed.js:423
// [Player] dies. compressed.js:416
Killing yourself just to log something may seem harsh but now you can write some snazzy asserts.
function assertTrue(test, message) {
if (!test) {
throw message;
}
}
It works, but Lord knows I wish there was a better way.

How to catch all javascript warnings and errors to an output div?

i'm using try, catch, for debugging, but warnings is not create exceptions. How to get all javascript warnings and errors to output div?
UPDATED:
If browser supports Afaik logging, how to get that log to string or output div?
UPDATED:
I found the way how to do that:
i can reload console.log function to my custom function an call native console.log function.
First of all, get rid of the try catch. Don't use try catch when you are debugging.
Second, you don't want to out errors to a div, use firebug or inspector for that - console.log();
Third, if you really want to do it: you could use try catch and in the catch, use something like
$('body').append($('div').html('variable for error message goes here'));
if you are using jquery
OR
document.getElementByTagName("body").appendChild( document.createTextNode("variable for error message goes here") );
if you have plain javascript
EDIT: try looking up ie debug bar , ie webDeveloper
I understand myself why someone may want something to actually happen when an error occours in the document. The answers above just say that you would use developer tools, but I needed things to actually happen, and after some searching, here's what I found...
If you wish to catch all errors that come through, you can put the following code into your file, best at the top:
window.onerror = function(errorMsg, url, lineNumber){
// any action you want goes here
// errorMsg is the error message itself.
// url should be the file presenting the error, though i have
// found that it only presents to me the address of the site.
// lineNumber is the line number the error occoured on.
// here is an example of what you could do with it:
alert("Error in " + url + " at " + lineNumber + ":\n" + errorMsg);
}
I, myself, like to output the errors to a div that contains them all, though you can do literally anything to this information that you could do with any other string passed to a function.
Here is an example of what may happen if you throw an error with a button using the code above:
Error in your.site.here at 1:
Uncaught ReferenceError: foo is not defined
For IE javascript debugging you can follow this guide:
http://msdn.microsoft.com/en-au/library/ie/gg699336(v=vs.85).aspx
Keep in mind that the developer tools window must be open prior to loading the page for the warnings and errors to appear in the console.
For webkit, (chrome, safari) developer console - here is a guide:
https://developers.google.com/chrome-developer-tools/docs/console
...Firefox also has a console

Javascript debugging in Safari web browser

I have a JavaScript error in my web project, and this error appears only in Safari 5 web browser. And the problem is Safari says just error message, but not file and line where this error appears. So, I can't find which code cause this error. Does anybody know how can I find code line causes this error?
Here is shot with debugger.
http://xmages.net/storage/10/1/0/d/c/upload/691ce801.png
Thanks for helping.
Click on the "stop sign" icon until it turns blue and then rerun the code. This should make the debugger halt on the line that generated the exception (and allow you to inspect the local variables and execution stack at that point).
thanks for helping!
Problem resolved now. It was jQuery template plugin. It causes this error when some DOM element in template has ID same as template variable name.
E. G.
var template = "<div id="foo">${foo}</div>"
var data = {foo: "bar"}
$.tmpl(template, data)
Solution: Rename ID of template variable name.
var template = "<div id="foo">${bar}</div>"
var data = {bar: "bar"}
$.tmpl(template, data)

Javascript error in IE

I have a page which is showing a javascript error in IE, stating which line the error is on, but the there are so many linked files I have no idea which line of code it is referring to.
Is there a way to find out which line / linked file it is relating to?? I'm sure I could fix the problem if I knew where it was.
Here is the error message from IE...
Message: 'null' is null or not an object
Line: 2231
Char: 5
Code: 0
URI: http://www.hpbtenancies.co.uk/location/JF/default.aspx
It happens on the line the error reports.. 2231 on default.aspx
dd.onchange = function(){ link.href = hrefOrig + dd.value;
The detailed error is
dd is null
Use Firefox which has better reporting and also use FireBug for even more flexibility in debugging javascript..
IE 8+ also has improved javascript debugging tools. In the console you will see
SCRIPT5007: Unable to set value of the property 'onchange': object is null or undefined
default.aspx, line 2231 character 5
Right-click on the page with the error, click 'View source', scroll down until you reach line 2231 - that's where your error is.

Firebug not showing Javascript errors for Rails applications

I have a Rails application, and when I have Javascript errors they are not showing in the Firebug console. I have 'Show javascript errors' and 'Show javascript warnings' selected.
When I insert javascript errors in a basic html file, the errors show as expected.
In the javascript of the Rails app, it only shows errors in rare cases.
For example i can insert nonsense like:
dfghaefb;
and no error is shown in Firebug. But if i insert a space in there Firebug does show the error:
dfgh aefb;
Any ideas? This is driving me nuts.
UPDATE:
Pumbaa80 was right, it's syntax vs runtime.
So I set up onerror:
onerror=errorHandler;
var error="";
function errorHandler(errMessage,url,line){
error="There is an error at this page.\n";
error+="Error: " + errMessage+ "\n";
error+="URL: " + url + "\n";
error+="Line: " + line + "\n\n";
error+="Click OK to continue viewing this page,\n";
alert(error);
return true;
}
And I have a method with an error:
function initForm() {
asdfs;
}
And it works when I call it outside of a method:
initForm();
but not in this case:
document.observe('dom:loaded', function() {
initForm();
});
Why is that?
dfghaefb;
produces a run-time error. Those errors may be suppressed by putting an onerror handler on the window or by trapping them in a try/catch in some way. In that case, Firebug won't show anything.
In contrast,
dfgh aefb;
is a syntax error, which is shown in the error console, regardless of try/catch and onerror.
Did you let the page load completely? I have a rails app running in front of me right now with firebug on and i entered dfghaefb; and yes it does throw an error!
ReferenceError: dfghaefb is not defined { message="dfghaefb is not defined", more...}
Running Firefox 3.6.3, Firebug 1.5.3 and MacOSX 10.5.6 :)
This may appear to be obvious, but be sure you wrap your inline JS using
<script type="text/javascript"> code </script>
Otherwise FireBug won't look at it at all.
I had the same, it wasn't showing anything and it was driving me crazy for ages, even if i had "Show javascript errors" in the console tab selected, it seems that it started working after I did "Enable all panels".
These kinds of problems cannot be answered without a test case.

Categories

Resources