Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get full DOM stack as a string

I want to get the full DOM stack as a string. As an example, please open Chrome, press F12 and type "document.all". This object represents the full DOM. I want to convert this object as a string. In Chrome you're able to explore the object, expand sections and view their content in the web debugger console. Is there any possibility to convert document.all as a string? Or a similar solution with gives me the full DOM stack? I don't just want the innerHTML/outerHTML, I want the content of literally everything what's defined in the current DOM. Any ideas? Thanks in advance...

EDIT: Okay, I think my question is kind of confusing, sorry for that. To clarify this: I want to get every property of every object which is defined, including stuff like "document.location", "document.location.hash", "window.innerHeight", "document.body.innerHTML", and so on, by using JavaScript.

like image 812
impuls23 Avatar asked Jun 14 '13 12:06

impuls23


1 Answers

As far as I know, there's no way to get every property of every object.

In at least some browsers (Chrome, for instance), you can get most of the DOM with outerHTML on documentElement (the root element, e.g., html):

var html = document.documentElement.outerHTML;

You'd have to check whether your other target browsers do. At a minimum, they'll have innerHTML on body:

var bodyHTML = document.body.innerHTML;

But in terms of the other things, I don't believe there's any way to get every property of every object. For instance, you can find the properties on window like this:

var key;
for (key in window) {
    // ...'key' is the property name, window[key] is the value...
}

...but that will only give you enumerable properties, not non-enumerable ones. And of course, you'd have to recurse into objects to get their properties (allowing for the fact that you can get to an object in more than one way — for example, window === window.window and there's also top, self, etc. to worry about; and similarly for document.all, document.forms, ...).

So unfortunately, while you can get a lot of the information you're talking about, I don't believe you can get it all.

like image 65
T.J. Crowder Avatar answered Oct 01 '22 16:10

T.J. Crowder