View Full Version : Screen scrape/accessing source of local browser via javascript...

03-26-2009, 10:43 PM
Would it be possible to pop open a local browser, and screen scrape this new browser via JavaScript? Is there a way to capture and dump into a file, the source code of a local browser instance with javascript?

Thanks for the help!

rnd me
03-26-2009, 11:30 PM
yes, if the pop-ups page is on the same domain as the main page.

you can look at the popup's window and contentDocument objects to get DOM handles to the page's code.

03-26-2009, 11:40 PM
Yeah, was just doing some further research, and realized the cross-browser scripting security pretty much prevents me from doing what I want to do. So if page A on domain1.com contains javascript that opens a new window, page B, with the url set to "domain2.com/index.htm", there is no way for javascript on page A to access the source or the DOM objects on page B, correct? I am actually looking to dump the source from page B into a textarea on page A, but doesn't sound like it's possible if they are from different domains...?

Thanks again for any insight!!

rnd me
03-27-2009, 12:04 AM
you can run the script from the second site, and export the data to the first.

this requires a bookmarklet that runs from the second page.
you can pass 2kb of data in the url, or with some browsers like firefox3, you can send a message to another window from a different domain of unlimited length.

there are also settings you can change to circumvent the domain restrictions.

is this something that just has to work for you alone, or many visitors to your site?

03-27-2009, 12:11 AM
Right now, if I could get it working for just myself, that would be great. In the above scenario, domain1 is under my control (I am designing and uploading the pages), domain2 is out of my control (i.e. a 3rd party site I have no access to other than trying to scrape whatever is served to a browser).

rnd me
03-27-2009, 06:04 AM
you might look into greasemonkey, it allows cross-domain requests...