问题
I'm using jquery within a firefox addon, but i keep getting tons of warning messages like below:
anonymous function does not always return a value
System JS : WARNING resource://gre/modules/XPIProvider.jsm -> jar:file:///c:/use
rs/usernameremoved/appdata/local/temp/tmprpnucw.mozrunner/extensions/jid1-I3FWz29roUS
8UA@jetpack.xpi!/bootstrap.js -> resource://gre/modules/commonjs/toolkit/loader.
js -> resource://gre/modules/commonjs/sdk/loader/sandbox.js -> resource://jid1-i
3fwz29rous8ua-at-jetpack/addon-name-removed/data/jquery.js:2435
Can you please let me know how can i ignore these errors? I can't find my console logs or errors because of them...
Jquery is included like this:
contentScriptFile: [self.data.url("jquery.js"),
self.data.url("zde.js"),
self.data.url("zdf.js")],
contentStyleFile: self.data.url("zd.css"),
Thanks!
回答1:
These warnings are a result of the javascript.options.strict (can be turned off and on again in about:config). Unfortunately, as far as I know, these warnings cannot be turned off on a file-by-file (or URI-by-URI) basis.
It appears that the SDK turns on this preference by default (in a normal browser it is turned off by default). There doesn't seem to be a way to change that via command line switches, so you'd have to locally patch the linked file in your copy of the SDK.
Those are valid warnings, but as you noted, pretty useless when it comes to third-party library code that you cannot fix anyway.
回答2:
This is indeed annoying. You can disable it from within your extension (for dev. only) as follows:
require("sdk/preferences/service").set("javascript.options.strict", false);
回答3:
I assume you are using cfx run to test your application. Sadly the direct console output is that cluttered and to my knowledge there isn't a way to only show the relevant logs of your extension.
If you are specifically interested in the console.log() and console.error()s, I recommend you use the Browser Console. There you can hide all output except for the Logging events.
来源:https://stackoverflow.com/questions/19692718/jquery-in-firefox-addon-causes-multiple-warnings