I want to use Reflect.parse in my JavaScript in Firefox.
MDN says to import this into the global object via
Components.utils.import("resource://gre/modules/reflect.jsm")
However, this results in the following error message:
Error: Permission denied for <file://> to get property XPCComponents.utils
I have tried this in Firefox 11 and Aurora.
How can I get access to Reflect.parse?
EDIT:
The error message is due to the following fragment:
Component.utils
There is no real solution to this problem. The documentation on Reflect.parse in the wiki is misleading, to say the least.
If you want a "pure" JavaScript solution in SpiderMonkey/Firefox, don't rely on Reflect.parse.
I see a lot of projects using the parser from Narcissus and I should have done the same.
EDIT: The Esprima project is an excellent implementation of the Mozilla Parser API. After replacing Reflect.parse with esprima.parse all my 150+ test cases were still green, except for 5 or so dealing with non-standard SpiderMonkey extensions like let expressions (which I find pretty impressive).
Related
I would like to use console.log(message) to write out some information to the browser console. However, I came across this url which seems to recommend against it:
https://developer.mozilla.org/en-US/docs/Web/API/Console/log
Are you currently choosing to use console.log(message) as part of your js code? If not then have you identified an alternative?
I agree with Mike C above-- console is generally available in most browsers, but you should probably remove console logs before a site gets pushed to production.
Additionally, some older browser might not have the console, and if you did accidentally leave in a console log, it would fire an error when it attempted to interact with with something that wasn't defined. As an extra failsafe, you can declare console and console.log in the global namespace if they are not detected, just in case:
if (!console) {
console = {
log: function () { //noop }
};
}
should I use a js function other than console.log(message)?
simple answer is yes, But also the console.log(message) is usaually used for testing purposes and for other relevant intentions like letting other developers interract with your js source code in some sort.
However.
You should not use it to log very important messages as this could be a hole your application presumably.
Hope it helps.
While the console object is not defined in the official Javascript standard, it is specified in:
Google Chrome
Mozilla Firefox
Internet Explorer 9+
Opera
Safari
Node.js
PhantomJS (since it uses V8 like Chrome and Node.js)
and more, I'm sure. As long as you're debugging in any of the environments which supports it, you're fine. You should be removing your logging statements before pushing to production anyway so as long as it works for debugging, it's nothing to worry about.
Is there a way to tell a page/project this it should ignore some javascript code/file? I am working on a project, that works well on all browsers, eccept IE8. I haven't tested for less than IE8, and I wont bother. Anyway. The error that I am getting is my language, but I'll translate to English.
Exception was thrown at line 4, column 12204 in https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
0x800a01b6 - A javascript runtime error occured: The object doesn't support the property or method 'getElementsByClassName'
If there is a handler for this exception, the program may be safely continued
This is just one of MANY errors like that.
And many more.
This is a huge problem for me. Is there any workaround for this? I am forced to keep this file, since the project is big, and other pages depend on this file
You could try replacing this line...
getElementsByClassName("classname")
with...
$(".classname")
TypeError: Unable to get value of the property 'childNodes': object is null or undefinedundefined
After making a long list of modifications to my application in order to support IE8, including:
running all of the views in their compiled form through W3C validator, setting up xdomain.js proxy to support CORS API calls, making some general restructures, etc.
I was very disappointed to find out that IE8 still throws this weird error at me, while IE9 works perfectly fine.
Making changes to the Angular-seo package to prevent it from running when the client is an IE browser.
Any ideas on what can it be?.
Make sure that all your tags are closed properly. I just spent hours trying to figure out what the problem was, until I noticed this in my code:
<span>some text<span>
I finally realized I didn't close the <span> tag properly. After that everything just worked.
Without the code you are running it is a bit difficult. However there is a command to use for debugging. First you need to identify which variable might not contain an object [i.e.
"object is null or undefined"].
For example, parent, then you can use
//next look to see if parent is something
if('undefined'==(typeof parent)) alert("variable empty:parent");
Once you find something that is empty that you are expecting to be an object then you can go trace back from there. Also use a browser debugged tool, to identify the line number of the error.
Often if using the child nodes, you may not have the right level or you need to access as an array i.e. you need something like.
parent.childNodes[0].childNodes[0].value
In IE you are also dealing with unsupported functions. So getElementById will work but some other similar ones do not. Again typeof can be useful.
//next ensure function supported
if( 'undefined'==(typeof document.getElementsByClassName) ){
alert("Not Supported"); // notice ^ no () required here
//...add code to handle differently when not supported
}
This may reveal if you can use a function
IE8 is so old and non-standards compliant it doesn't support childNodes[]. http://quirksmode.org/dom/core/#t70
I was iterating over properties of document when I ran into an interesting phenomena in Firefox, document claims to support the property domConfig although MDC says it isn't implemented but when I try to retrieve the property I get an exception:
Error: uncaught exception: [Exception... "Component returned failure code: 0x80004001 (NS_ERROR_NOT_IMPLEMENTED) [nsIDOM3Document.domConfig]" nsresult: "0x80004001 (NS_ERROR_NOT_IMPLEMENTED)" location: "JS frame :: javascript:alert(typeof(document.domConfig)) :: :: line 1" data: no]
The following shows the behaviour, both Chrome and IE are consistent (I haven't checked Opera) in saying that domConfig is not a property of window but Firefox claims it is but can't retrieve it (copy paste into URL field since I can't get markdown to give a link).
/* true in FF, false in other browsers */
javascript:alert("domConfig" in document)
/* exception in FF, 'undefined' in other browsers */
javascript:alert(typeof(document.domConfig))
What's going on here?
Pointy's right, domConfig is exposed in an interface (DOM Level 3 Core Document - in Mozilla's source it's called nsIDOM3Document), but is not implemented (see nsDocument::GetDomConfig()). typeof works by first getting the value, then determining its type (and not from the interface definition), so it's not surprising typeof document.domConfig throws an exception.
As for why it's been done this way, the bug this code was added in doesn't have any discussion about that, so we can only guess.
My guess is that for specifications Mozilla intended to implement it made sense to finalize ("freeze" in Mozilla's terms) the interfaces, so that they could be used from binary code without further modifications after new properties/methods of the interface got implemented. And it didn't seem to matter much one way or another.
If you're interested in hearing from the developers, you could ask in mozilla.dev.tech.dom or mozilla.dev.platform.
I'm having problems with getting decent JavaScript error invormation in a Production environment.
When I'm developing I can just attach a debugger and (usually) fix the problem.
When I get the same error in a production environment however at best I see is an error report that looks like this:
Error: Object doesn't support this property or method
Url: SomePage
Line: 42
Char: 13
Which doesn't help me very much - I can't see the rendered page and so I have no idea what line 42 looks like.
Is there any way for me to log the entire rendered page contents whenever an error like this occurs? (So line 42 of the output is the line where the error occured)
While I'm at it, are there any other techniques that I can use to help with getting useful error information from JavaScript (without need to break into the debugger) - failing that is there any way that I can structure my JavaScript slightly differently to help getting decent debug information?
I'm predominantly interested in IE - this is the browser that tends to cause me most problems.
I don't think you'll be able to get the exact original HTML source of the page back in all pages and all browsers.
Regarding debugging, you could use a logging library such as log4javascript (disclaimer: I wrote it) and intersperse logging calls in your code. log4javascript enables you to send logging messages back to the server via Ajax.
Unfortunately, IE has by default the most utterly useless error reporting. The script and line number reported in the error are essentially guaranteed to be absolutely wrong. You can, however, install the IE developer tool bar (for IE7 and older, it's built into IE8) from Microsoft, which can help track down the error source.