Question: Hi this may be a silly question, but I can't find the answer anywhere.
I'm writing a chrome extension, all I need is to read in the html of the current page so I can extract some data from it.

here's what I have so far:

```
<script>
    window.addEventListener("load", windowLoaded, false);
    function windowLoaded() {
        alert(document.innerHTML)
      });
    }
</script>

```

Can anybody tell me what I'm doing wrong?
thanks,

Answer: 
```
function windowLoaded() {
    alert('<html>' + document.documentElement.innerHTML + '</html>');
}
addEventListener("load", windowLoaded, false);

```

~~Notice how `windowLoaded` is created before it is used, not after, which won't work.~~

Also notice how I am getting the innerHTML of `document.documentElement`, which is the `html` tag, then adding the `html` source tags around it.
Use `document.documentElement.outerHTML`. (Note that this is not supported in Firefox; irrelevant in your case.) However, this is still not perfect as it doesn't return nodes outside the root element (`!doctype` and possibly some comments or processing instructions). The `document.innerHTML` property is, AFAIK, specified in HTML5 specification, but currently not supported in any browser.

Just FYI, navigating to `view-source:www.example.com` also displays the entire markup (Chrome & Firefox). But I don't know whether you can work with it somehow.