Math.random() javascript function *undefined* on Chrome

Alessio Arleo

In first place, I am convinced that this is a trivial question, but I cannot understand why this is happening and I couldn't find an answer anywhere else. I googled my issue with little success, but if I missed something and just wasted your time please point me in the right direction and accept my humble excuses.

That said, here is what happens. I am building a simple script to display a graph drawn by a distributed algorithm (giraph) and I am working on Linux. I import all the libraries and, in particular, jQuery and everything works in Firefox (version 36.0.1). Switching to Chrome (version 41.0.2272.89 (64-bit)), the page stops working. Investigating the issue, I found out that the error was inside the jQuery.extend() function into the jQuery library, at the following line:

expando: "jQuery" + ( version + Math.random() ).replace( /\D/g, "" ),

In fact, trying to invoke Math.random() into the browser console leads to:

> Math.random();
> Uncaught TypeError: Undefined is not a function

Anyway, while typing the console autocompletes the "Math" variable, with the following result:

> Math
> function (){return "";}

This does not happen with Chrome on MacOS X Mavericks. Did anybody experience this kind of behaviour before?

EDIT: Unfortunately, I don't think that this is a namespace conflict. In my library I import only one other library (other than jQuery), which is Sigma js. As suggested, I wrote Math in the console and tried to understand which library did override Math (using "Show Function Definition"), with the following result, taken from a file named "VM53" (which I did not write and/or linked directly).

(function (){
    for (var i in window)
    {
    try {
            var jsType = typeof window[i];
            switch (jsType.toUpperCase())
            {                   
                case "FUNCTION": 
                    if (window[i] !== window.location)
                    {
                        if (window[i] === window.open || (window.showModelessDialog && window[i] === window.showModelessDialog))
                            window[i] = function(){return true;};
                        else if (window[i] === window.onbeforeunload)   // To try to fix onbeforeunload pop ups some users report seeing but I can't replicate.
                            window.onbeforeunload = null;
                        else if (window[i] === window.onunload)
                            window.onunload = null;                             
                        else
                            window[i] = function(){return "";};
                    }
                    break;                          
            }           
        }
        catch(err)
        {}      
    }

    for (var i in document)
    {
        try {
            var jsType = typeof document[i];
            switch (jsType.toUpperCase())
            {                   
                case "FUNCTION":
                    document[i] = function(){return "";};
                    break;                  
            }           
        }
        catch(err)
        {}      
    }

    try {
        eval = function(){return "";};              
        unescape = function(){return "";};
        String = function(){return "";};
        parseInt = function(){return "";};
        parseFloat = function(){return "";};
        Number = function(){return "";};
        isNaN = function(){return "";};
        isFinite = function(){return "";};
        escape = function(){return "";};
        encodeURIComponent = function(){return "";};
        encodeURI = function(){return "";};
        decodeURIComponent = function(){return "";};
        decodeURI = function(){return "";};
        Array = function(){return "";};
        Boolean = function(){return "";};
        Date = function(){return "";};
        Math = function(){return "";};
        Number = function(){return "";};
        RegExp = function(){return "";};

        var oNav = navigator;
        navigator = function(){return "";};
        oNav = null;            
    }
    catch(err)
    {}

})();
Glen Swift

Something overrides Math in your code.

Execute Math in your chrome console. Execute context menu on it and select "Show function definition". This will probably lead you to "Sources" panel and show script where it is being overriden.

EDIT: this is chrome extension called notscripts. Disable it. Here is the source code for proof: webarchive

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

javascript TypeError: Math.random is not a function on chrome

From Dev

Javascript Math.random() not *that* random…?

From Dev

Math & JavaScript | Random chances

From Dev

Chrome/Chromium doesn't know JavaScript function Math.sign

From Dev

Chrome/Chromium doesn't know JavaScript function Math.sign

From Dev

Javascript - Math.random as parameter

From Dev

Why Math.random() type is number and Math.random is function?

From Dev

Javascript math function resolver

From Dev

chrome - run javascript function from browser console "undefined"

From Java

Is a function that calls Math.random() pure?

From Dev

math.random function in lua to position object

From Dev

math.random function with step option?

From Dev

math.random function with step option?

From Dev

math.random function in lua to position object

From Dev

Math.Random in function always the same result

From Dev

Math.random/floor with a function and onclick?

From Dev

Math.random and web programming in JavaScript

From Dev

Javascript Math.random() and conditional expressions

From Dev

Generate a random math Equation using Random numbers and operators in Javascript

From Dev

Chrome claims simple function is undefined

From Dev

Javascript function returns undefined

From Dev

IIFE, javascript, function undefined

From Dev

Javascript: undefined as a function parameter

From Dev

Javascript - Undefined is not a function

From Dev

Undefined is not a function - JavaScript

From Dev

Javascript setTimeout - undefined is not a function

From Dev

Javascript undefined array in function

From Dev

undefined is not a function - error in Javascript

From Dev

Undefined function in javascript

Related Related

HotTag

Archive