views:

48

answers:

5

Hi!

I'm trying to build an application that reads - and preferably detects the changing of (through an event or smthg like) - the browser current HTML.

My main purpose is to build some kind of feature that enables single sign-on to some pages, so I'd need to know every time a page has completed loading to check the HTML and set some fields values, for example.

I'm aware that implementation for different browsers can differ, but IE and/or Firefox would be a great start.

Even googling all around I couldn't get neither close to how can I achieve this. I imagine that maybe, but just maybe, I could attach some kind of control to the browser's window using Windows API, but I'm trying to believe (until now, at least) that there's something easier. :)

Any kind of idea would be really appreciated.

Regards,

Filipe

+3  A: 

Doing this from an outside app is going to be an outlandish task. You would have to set up dozens of the most complicated querying mechanisms, and may be shut down by security measures. Stuff like this is what browser extensions are for.

Plus, even when the source code has loaded completely, it still doesn't mean the page is ready. In an extension, you would just hook into the onLoad event and have a clean, properly parsed DOM at your disposal.

Maybe it's possible to write a number of extensions, one for each browser, and have those extensions communicate with your application. That way, it could actually be pretty easy. The extensions would listen for the onload event, and then pass all the HTML on for you. (This is a major privacy issue no matter which way yo do it, because that HTML could contain all sorts of things, but that's a different story). Whether it can be done, depends on whether the extension models allow communication with outside processes.

Pekka
Outlandish verging on simply-not-possible. The only way that I can think of doing it is to hook directly in to the particular operating system's TCP/IP stack. There is no conceivable pay-off that it would make it work the effort.
Adam Crossland
+1 to get you to 10K rep! Well done :) ... and for answering an outlandish question!
Daniel Vassallo
Cheers Daniel! :) :)
Pekka
+1  A: 

I'm guessing there's a more direct way to do this, but what about Greasemonkey? You could write a GM script that grabs the HTML of the current page and then sends it to your app via Ajax (your app would have to be running a tiny HTTP server, of course). If GM is too limited you could also write a Firefox extension that would give you some more sophisticated options.

Jordan
A: 

To do this with Internet Explorer, you are going to have to build a Browser Helper Object to hook into the events that the browser publishes regarding the disposition of the current page. This is by no means a trivial task and will require a good deal of Windows-specific programming. I do not believe that it is possible without writing a BHO, and technically, the BHO is 'inside the app,' as you have to install it into IE.

Browser Helper Objects

Adam Crossland
A: 

How about creating a local proxy? There's an ad-filtering application called Proxomitron that could be a model for you.

David Peters
A: 

I've found a way to do that in Internet Explorer using ShDocVw (Microsoft Internet Controls): http://msdn.microsoft.com/en-us/library/aa752044%28VS.85%29.aspx.

ShDocVw contains some classes that allow you to monitor existing and new browsers navigation (docCompleted, download, etc.). Next step is to figure out how to write to DOM (probably it's very straight, I didn't try yet).

Firefox will be another novel, but IE is enough by now.. :)

Thank you all.

Filipe

jfneis
Nice! You can edit your question and add the information there, that will be helpful for future generations.
Pekka