0

What javascript program will list all the native / host / platform objects that are provided "spontaneously" in a browser?

If no such program can be written is there any other way of generating such a list?


Clarification of "native / host / platform objects" as requested by this answer

Examples:

using
window.navigator.userAgent =
"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3) Gecko/20100423 Ubuntu/10.04 (lucid) Firefox/3.6.3"

some native JavaScript objects (some of which happen to be constructors)

Array, Boolean, Date, Function, Number, Object. RegExp, String
Error, Iterator, JSON, Math

some DOM host objects

Image, Option

some other platform objects

Worker, XMLHttpRequest, XPCNativeWrapper

references:

See also


This is minimally effective:

javascript:
    alert("using:\n"+window.navigator.userAgent);
    list=[];
    for( i in window) list.push(i);
    alert("found:\n"+list.sort().join("\t"));
    list=[];
    for( i in window) list.push([typeof eval("window."+i),i].join("\t"));
    alert(["found:",list.sort().join("\n--------------\n")].join("\n"))

produces

using:
     Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3)
          Gecko/20100423 Ubuntu/10.04 (lucid) Firefox/3.6.3

found:
Components  XPCNativeWrapper    XPCSafeJSObjectWrapper  addEventListener    
alert   applicationCache    atob    back    blur    btoa    captureEvents   
clearInterval   clearTimeout    close   closed  confirm content controllers 
crypto  defaultStatus   directories disableExternalCapture  dispatchEvent   
document    dump    enableExternalCapture   find    focus   forward 
frameElement    frames  fullScreen  getComputedStyle    getInterface    
getSelection    globalStorage   history home    i   innerHeight 
innerWidth  length  list    localStorage    location    locationbar 
menubar moveBy  moveTo  mozInnerScreenX mozInnerScreenY name    navigator   
netscape    open    openDialog  opener  outerHeight outerWidth  
pageXOffset pageYOffset parent  personalbar pkcs11  postMessage 
print   prompt  releaseEvents   removeEventListener resizeBy    
resizeTo    routeEvent  screen  screenX screenY scroll  scrollBy    
scrollByLines   scrollByPages   scrollMaxX  scrollMaxY  scrollTo    
scrollX scrollY scrollbars  self    sessionStorage  setInterval 
setResizable    setTimeout  showModalDialog sizeToContent   status  
statusbar   stop    toolbar top updateCommands  window

and (selectively edited)

found:
...
--------------
function    $
--------------
function    PR_normalizedHtml
--------------
function    XPCNativeWrapper
--------------
function    XPCSafeJSObjectWrapper
--------------
...
--------------
object  Components
--------------
object  Markdown
--------------
object  PR
--------------
object  StackExchange
--------------
...
--------------
object  jQuery15205241375142988156
--------------
...
--------------
object  window
--------------
...
Community
  • 1
  • 1
Ekim
  • 949
  • 1
  • 8
  • 9
  • Can you provide an example of the type of objects you're looking for? "spontaneous objects" or "native objects" are not well defined terms that fully define what you're looking for? – jfriend00 Aug 17 '11 at 04:07
  • "spontaneously" qualifies the manner of manifestation of the objects not the objects themselves - and the term was quoted to make this deferral explicit - the references explicitly qualify the terms "native" and "host" objects formally – Ekim Aug 17 '11 at 04:45
  • When I look at the Window object in the Chrome debugger, I see all the example you listed in your question as properties on the Window object except for XPCNativeWrapper (which I don't think is supported in Chrome). It appears to me that Germán Enríquez's answer would do what you want. The Window object in a browser is the "global" namespace so this makes some logical sense. – jfriend00 Aug 17 '11 at 05:06
  • `javascript: list=[]; for( i in window) list.push(window[i]); alert(list.join(",").match(/(Array|Boolean|window)/g).join("\n===\n"))` shows `Boolean` is not listed (the atomic object `Array` is also not identified but this elementary search does not reveal that) using "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3) Gecko/20100423 Ubuntu/10.04 (lucid) Firefox/3.6.3" – Ekim Aug 17 '11 at 05:45

2 Answers2

0

I'm not sure what you want to do, but if you want all methods from the windows object (methods that usually are called without an object instance prefix), you can just do this:

var stuff = new Array(); for(var i in window){ stuff.push(window[i]); }

Then, you can use the stuff array to see ALL of what is contained in the window element (as objects). Of course it's not adviceable to use methods throught that array. Please note that this will list ALL properties on the window element.

If you wan't something else, could you provide us with an example of which data would you like to obtain from which elements?

  • `window` itself is such an object that should be enumerated in the list generated by the program – Ekim Aug 17 '11 at 04:53
  • `Boolean` is missing: `javascript: list=[]; for( i in window) list.push(window[i]); alert(["found:\n",list.join(",").match(/Boolean/g)])` – Ekim Aug 17 '11 at 05:36
  • `javascript: list=[]; for( i in window) list.push(window[i]); alert(["found:\n",list.join(",").match(/Number|String/g)])` shows `String` and `Number`are absent ... – Ekim Aug 17 '11 at 05:40
  • `var stuff = new Array(); for(var i in window){ stuff.push(i); }` is "more correct" but still does not enumerate all the objects given as examples. – Ekim Aug 17 '11 at 05:59
0

Different browsers expose different things on the window object. Chrome appears to expose pretty much everything one could think of being in the global namespace including all the built-in types like Array and Boolean. Firefox seems to have the opposite tactic - exposing as little as possible there.

You can see what any given browser exposes in this fiddle: http://jsfiddle.net/jfriend00/6KRpK/.

I'm not aware of any specification that requires all globally recognized names (whether built-in types or global language methods like parseInt()) to be enumerable by a script other than the ones that must be on the window object.

As such, I think this means you're out of luck if you want a method that works in all browsers. For now, you can get a pretty good list (though a few are Chrome-specific) out of Chrome. Not so out of Firefox.

Some similar territory covered in these other SO posts:

List of global user defined functions in JavaScript?

JavaScript: List global variables in IE

Community
  • 1
  • 1
jfriend00
  • 683,504
  • 96
  • 985
  • 979
  • oh well ... perhaps a raw examination of the browser binaries can identify predefined entities assuming the names are embedded in the binaries literally – Ekim Aug 17 '11 at 08:00