0

Is there a way to find every unique class definition used in a WebPage? For example, if a web page has three unrelated JS classes Dog, Cat, and Mouse, but I do not know that these classes exist, how would I discover them?

//returns all the JS classes in a document
function getAllDocumentClasses(){

}

This would be a function I would run in the chrome console.

Context: I'm preparing some documentation on extracting data from web pages using javascript. One approach to do this is to investigate the classes used in a library, for example, to see all the instances of a Highcharts and then extract the data used in that Highcharts instances. But if we do not know which libraries a web page is using, then this is more difficult.

Edit: Seems like this might not be possible with javascript. But if you go to Chrome Developer Tools and type window., then you can browse through available classes in the window.

window

ANimator120
  • 2,556
  • 1
  • 20
  • 52
  • 3
    If the classes are not in a scope you can access there is not much you can do to grab it unless you are writing some sort of spider that can find every JavaScript file/inline tag and somehow parses it to find classes. – epascarello Jun 21 '22 at 20:00
  • 3
    It's also worth pointing out, a class names in Javascript don't have to be unique. It's very possible to have multiple `Dog` classes, but them been totally different implementations.. – Keith Jun 21 '22 at 20:03
  • Additionally, old-style classes (using constructor functions) are nigh indistinguishable from functions without inspecting instances, and, if the code is properly designed, most instances won't be visible. – outis Jun 21 '22 at 20:10
  • Does this answer your question? "[How to enumerate list of available classes in javascript es6](//stackoverflow.com/q/45709815/90527)", "[Javascript ES6 class definition not accessible in window global](//stackoverflow.com/q/37711603/90527)", "[Find all classes defined in scope of script](//stackoverflow.com/q/40561046/90527)" – outis Jun 21 '22 at 20:12

0 Answers0