How to trigger `undefined is not a function` in modern broswers? - javascript

I remember getting this error a lot a while before. Today I wanted to show it to a friend unfamiliar with Javascript. Chrome and Safari instead gave me something like:
> const o = {};
< undefined
> o.doge()
< TypeError: o.doge is not a function (In 'o.doge()',' 'o.doge' is undefined)
Chrome and Firefox seem to be user-friendly as well.
How can I get an original error, without this helpful message?

You will never get that error in a modern browser; the error comes from js engine itself not the browser; and if there are no others other than that Type Error, modern engines will return a more developer friendly error by applying a (similar) /(w+)/ regex on what ever typed before () and placing it in the error message check out:
v8 (chrome) message templates that will make the error string (line 51, 52):
T(CalledNonCallable, "% is not a function")
and SpiderMoneky (mozilla) message templates (at line 51, 54):
MSG_DEF(JSMSG_NOT_FUNCTION, 1, JSEXN_TYPEERR, "{0} is not a function")
non-callable test case in v8 and a SpiderMokney test case .
So the only way to a undefined is not a function error message in a modern browser is doing undefined() :)
undefined()

you can just try to find and download an older version of the browser which logged the original error. (if that version is still publicly available).

Related

Problems reading JSON file in D3 javascript in some (not all) browsers

I get this error in Chrome immediately after reading a JSON file. It works correctly in Safari and Firefox.
console.log ("event -> "+ postcards.nodes[0].node.event); // "tally" in Safari "TypeError: Cannot read property 'node' of undefined" in Chrome.<
Is there a limit to the levels in a nested JSON file? I generate the JSON from a Drupal view. Here here is the start:
{"nodes":[{"node":{"w1":"","w2":"1","w3":"","w4":"", ...<
Here is the Javascript:
d3.json(
"/sites/default/d3_files/json/toronto-wards.json",
function(error,wards) {
d3.json("/postcards-json", function(error, postcards) {
console.log ("event -> "+ postcards.nodes[0].node.event); // tally in Safari
I'm using macOS and my friends using Windows get the same error in Firefox.
As per request here is what I think is the XHR message:
d3.min.js:1 XHR finished loading: GET "http://www.stopplastics.ca/postcards-json".
Does the following work for you?
Promise.all(
d3.json("/sites/default/d3_files/json/toronto-wards.json"),
d3.json("/postcards-json")
)
.then(
function([wards,postcards]) {
console.log ("event -> "+ postcards.nodes[0].node.event); // tally in Safari
Some browsers may not support deconstructing arrays so probably better to try the following for older browsers (non Chrome and Firefox):
Promise.all(
d3.json("/sites/default/d3_files/json/toronto-wards.json"),
d3.json("/postcards-json")
)
.then(
function(results) {
var wards=results[0],postcards=results[1];
console.log ("event -> "+ postcards.nodes[0].node.event);
}
);
According to the comments your drupal end point providing the JSON needs authentication so gives you empty data when you're not loged in.
Error has maybe nothing to do with the browser used but depends if you're loged in or not.
The problem was caused by the Drupal view not being created correctly. Nothing to do with the Chrome browser.

FireFoxDriver JavaScript errors does not show in FireFox browser

I'm using the following code to capture JavaScript errors when running Selenium tests:
public static void AssertNoJavaScriptErrorsInLog(this RemoteWebDriver driver)
{
var errorStrings = new List<string> { "SyntaxError", "EvalError", "ReferenceError", "RangeError", "TypeError", "URIError" };
var jsErrors = driver.Manage().Logs.GetLog(LogType.Browser).Where(x => errorStrings.Any(e => x.Message.Contains(e))).ToList();
if (jsErrors.Any())
{
Assert.Fail("JavaScript error(s):" + Environment.NewLine + jsErrors.Aggregate("", (s, entry) => s + entry.Message + Environment.NewLine));
}
}
One of my tests intermittently reports an error:
Assert.Fail failed. JavaScript error(s):
TypeError: doc.documentElement is null
TypeError: doc.documentElement is null
Trying to locate the error I look in the console of the FireFox browser which just ran the failed tests, but it's empty!
Why can't I see the JavaScript error in the browser console?
You might be experiencing the following fresh selenium issue:
Some new browser logs are not captured
As a workaround, consider downgrading selenium to 2.52.
Also, from time to time there are compatibility issues between selenium and firefox with a wide range of symptoms - play around with firefox versions (you can download older versions here) and see if you still cannot catch the js error on the console.

MIDI.js Error code:1, can't requestMIDIAccess

I am trying to use MIDI.js to play sounds in the browser.
https://github.com/mudcube/MIDI.js
It works in the chrome browser on one of my computers, but not on my other one (which is a chromebook), or on the chrome browser on two of my friends computers.
it prints to the console
"uh-oh! Something went wrong! Error code: 1" MIDI.js:349
which refers to this part of MIDI.js
navigator.requestMIDIAccess(function (access) {
plugin = access;
output = plugin.getOutput(0);
if (callback) callback();
}, function (err) {
console.log("uh-oh! Something went wrong! Error code: " + err.code );
});
i found this post which seems to be referring to the problem i'm experiencing but i'm not quite sure
https://plus.google.com/+ChrisWilson/posts/cs4J6sS9qmJ
where it says to swap some parts of the code for some reason I couldn't understand
navigator.requestMIDIAccess( successCallback, failureCallback );
becomes:
navigator.requestMIDIAccess().then( successCallback, failureCallback );
but after replacing that part on MIDI.js 344, i get the error message
Uncaught TypeError: Cannot call method 'then' of undefined
Any help on how to fix this problem so it works in all browsers, or at least all chrome browsers, would be greatly appreciated. Thankyou
Chromebooks don't have Web MIDI API support yet (nor on Mac or Windows if you don't enable it, or Windows if you're not running Canary).

Firefox add-on won't open its own file as a new xul window.

My add-on creates a FireFox File menu command that triggers callback function 'launchApp'.
function launchApp() {
var ww = Cc["#mozilla.org/embedcomp/window-watcher;1"]
.getService(Components.interfaces.nsIWindowWatcher);
var appUrl='chrome://mrT2/mrT00.xul'; // production (fails)
var appUrl='file:///C:/mpa/##mrT-2.0/mrT00.xul'; // testing (works)
var win = ww.openWindow(null, appUrl, "mrT2-window", "chrome,resizable", null);
// Summary of results of ww.openWindow() for various appUrl values:
// 'chrome:///mrT2/mrT00.xul' 'No chrome package registered for ...' (true)
// 'chrome://mrT00.xul' 'Invalid chrome URI: /' (true)
// 'chrome:///mrT00.xul' and 'chrome://mrT2/mrT00.xul' seem valid yet both give:
//Error: NS_ERROR_ILLEGAL_VALUE: Component returned failure code: 0x80070057 ...
// ... (NS_ERROR_ILLEGAL_VALUE) [nsIWindowWatcher.openWindow] (unexplained)
return true;
The above code works nicely and is great for testing mrT00.xul (because it collects the file directly from where I am editing it).
However when I interchange the two appUrl vars to try and open the exact same file as shipped via the xpi (and now internal to firefox) I get the dreaded 'illegal value' 0x80070057.
After 2 long days of research and study I cannot fault my code. Can you?
Otherwise, how may I begin tracing nsiWindowWatcher to pinpoint the error?
Bad things can happen when an extension attempts to open a xul file outside the /content directory or inside it when the chrome.manifest file in the .xpi root is not in order. Firefox handling of both these situations is not above reproach, warnings being offered in neither case.

TwitterWidget within SilverStripe

I am trying to integrate TwitterWidget within SilverStripe.
That's the plugin I am trying to use:
https://twitter.com/about/resources/widgets/widget_profile
If I put this code in a simple *.html file the widget works. Unfortunately I get an error if I try to use it in a *.ss file.
I downloaded the source code to find out where the error occurs. After several hours I found something pretty confusing:
That's the piece of code where the error occurs:
document.write('<div class="twtr-widget" id="'+this.id+'"></div>')
FireBug:
uncaught exception: [Exception... "An attempt was made to use an object that is not, or is no longer, usable" code: "11" nsresult: "0x8053000b (NS_ERROR_DOM_INVALID_STATE_ERR)" location: "http://www.domain.com/mysite/javascript/widget.js?m=1321187964 Line: 257"]
LeftAn...8532904 (Zeile 883)
function() {return new ActiveXObject('Microsoft.XMLHTTP')},
After a few refreshes sometimes FireBug reports:
An attempt was made to use an object that is not, or is no longer, usable
[Bei diesem Fehler anhalten] document.write('<div class="twtr-widget" id="'+this.id+'"></div>')
Google Chrome JavaScript Debugger:
Uncaught TypeError: Object #<Document> has no method 'write' //widget.js:257
TWTR.Widget.init //widget.js:257
TWTR.Widget //widget.js:211
(anonymous function) //?stage=Stage&flush=1:117
f.extend._Deferred.e.resolveWith //jquery-1.6.4.min.js:2
e.extend.ready //jquery-1.6.4.min.js:2
c.addEventListener.C //jquery-1.6.4.min.js:2
This is a little incomplete to debug, but why not use one of the readily available widgets? Like http://www.silverstripe.org/twitter-widget-pack-widget/

Categories