Detect DOM modification in Internet Explorer - c++

I am writing a Browser Helper Object for ie7, and I need to detect DOM modification (i.e. via AJAX).
So far I couldn't find any feasible solution.

You want to use IMarkupContainer2::CreateChangeLog.

The best thing I could recommend is the Internet Explorer Developer Toolbar which allow you to view changes in the DOM.

Related

Controlling Internet Explorer in order to enter username/password

I was looking into trying to get my C++ application to do the following:
Open internet explorer
Open a webpage
Enter a name and password into specific forms in the webpage
Click the submit button on the webpage to open a new page
From my searching on the Internet it seems like using COM may make this possible, although I may be incorrect on that. I am doing my best to learn COM at the moment but some help would be great. I'm looking to do this without using MFC.
I have noticed this question which I kind of what I am looking for but I am having trouble understanding the suggested solutions. For example, I do not have a IWebBrowser2 option in my toolbox.
EDIT:
To make my question clearer, I had this task complete in a C# version by simply running a coded UI test but this will not work with C++. I am looking to open IE (not in the application itself), find the username and password forms, pass them string, then find the submit button on the page and click it.
This is very possible from c++. You will have to dive into the winapi to do some Keystroke stuff as well as window handling.
I'm not going to go into all of the code, but you have to do something like the following:
Start ie (if you give it a command line arg with the webpage, it will
open that page).
Make sure the ie window is focused (either just wait
if you want to keep it simple or use window's api to go through each
open HANDLE and find the window you want)
Use SendInput to send an Alt + D (to gain focus to the url bar, in firefox it will be a CTRL + L instead)
Use SendInput and javascript injection to modify the DOM as necessary
You can also submit the form (after everything is as you want it) using the above JS injection capability.
Yes, it is possible, but you have to embed a web browser control in your application, and it is not straightforward (I don't think you can automate DHTML in an external instance of Internet Explorer via COM).
I see that you don't want to use MFC, and this complicates even more the problem. Perhaps you can do it via ATL, I advise against even trying to do it without a framework.
If you could use MFC, then you could use a CDHtmlDialog form and access the underlying COM interfaces to automate the actions.
In the past, I developed an MFC application that used HTML as its user interface, but I used the CDHTMLView class that you can find here: http://www.codeproject.com/Articles/1783/Integrating-DHTML-into-MFC-Views
You can use this as an entry point for learning how to deal with DHTML events and how to play around with the IWebBrowser2 interface.
You should really take a look at WebDriver which is able to do exactly what you are describing. See (http://code.google.com/p/selenium/wiki/InternetExplorerDriverInternals) for more information about the InternetExplorerDriver internals. Even if you are not able to use the project directly, you can certainly browse the source to get a better idea of how what you want to do can be achieved.
What you want to do makes not much sense.
There are many APIs available to embed a browser view into your program. For example Qt offers this.
Then you can just do your HTTP POST request yourself and display the answer you get in your browser view.
That is a much cleaner solution.
Pro tip: Don't use Internet Explorer.

Firefox extension and nsIMutationObserver

I am a Firefox C++ extension newbie. I need to get access to DOM mutation events in my extension during page load. Firefox by default doesn't send DOM mutation events during page load to improve page load performance.
I understand the reason, but understanding the consequences I still need access to the DOM mutation events. I read somewhere that nsIMutationObserver still gets invoked during page load (and is bit more efficient then DOM mutation events as don't have to walk up the DOM tree looking for listeners), however it's only available to native code.
So I have following questions :
Is nsIMutationObserver and nsIMutationObserver2 available to Firefox extensions?
If yes, how can I write a simple Firefox extension in C++ to get access to it and expose it to Javascript?
If folks can point me to a existing extension that does this forwarding from C++ land to JS, that will be highly appreciated.
Or can I use JS-CTypes to get access to that functionality from my Javascript based extension?
BTW, I asked this question in Firefox's extension forum, but no replies there.
Thanks in advance
Is nsIMutationObserver and nsIMutationObserver2 available to Firefox extensions?
Yes, binary Firefox extensions can use it. Of course, the drawback is that your binary XPCOM component will only work with one Firefox release - it will have to be recompiled for each new release.
If yes, how can I write a simple Firefox extension in C++ to get access to it and expose it to Javascript?
You create an XPCOM component (see example code) and implement nsIMutationObserver interface. You then attach this mutation observer to documents like this:
NS_IMETHODIMP
MyMutationObserver::AttachToDocument(nsIDOMDocument* document)
{
nsCOMPtr<nsINode> node(do_QueryInterface(document));
node->AddMutationObserver(this);
}
For reference: nsINode interface
If folks can point me to a existing extension that does this forwarding from C++ land to JS, that will be highly appreciated.
Sorry, don't know any. But your XPCOM component can expose an additional interface that your JavaScript code will use - e.g. to register a callback. You have to consider that it might not be safe to run JavaScript when the mutation observer gets called. Important methods here: nsContentUtils::IsSafeToRunScript() and nsContentUtils::AddScriptRunner() (see nsContentUtils.h).
Or can I use JS-CTypes to get access to that functionality from my Javascript based extension?
No, you cannot. These are Gecko internals, they aren't exposed to js-ctypes.
A binary extension can use nsIMutationObserver, but unless it's very very careful about what it does when it's notified (see the big WARNING above the interface declaration) it'll cause crashes and various other broken behavior and is likely to introduce security bugs. Like any other internal API, this is a footgun; probably a fatal one if not used extremely carefully. Things that are fine to do in a DOM mutation listener are NOT OK in an nsIMutationObserver.

Accessible Facebook Like Button

Has anyone created a custom Open Graph solution that queries the number of likes and creates an accessible button? Facebook's iFrame and XFBML solutions are both completely inaccessible via the keyboard and screen readers -- and no one seems to care.
The count is super easy to grab, it's the like URL that I'm not sure about. The anchors inside of Facebook's iFrames don't even have hrefs, so I'm currently digging through their scripts for some actionable targets.
Hit this URL with JS or in a browser and you'll get an ID and # of shares (are likes different though? better than nothing i guess): https://graph.facebook.com/http://putyourUrlhere
Any idea how to trigger a like without Facebook's provided code? It's ok if the button is only accessible with Javascript on since screen readers can use JS. Their code obviously requires it anyway. Has anyone done something like this with the Javascript SDK?
I'm trying to figure out if this is even possible, so I'd appreciate any insight!
PS -- iFrames are not inherently inaccessible. The problem is that Facebook's code inside of it is not. http://webaim.org/techniques/frames/#iframe
Facebook finally got around to making the like button keyboard accessible. Just took a while.
https://developers.facebook.com/docs/reference/plugins/like/
It is not supported. Automated likes would compromise the authenticity of the Graph.

How to access DOM of a web page in QtWebKit?

How to access DOM of a web page in QtWebKit?
I don't see any methods exposing DOM in QtWebKit...
Currently, you need to do DOM manipulation via JavaScript, injected via
QVariant QWebFrame::evaluateJavaScript(const QString & scriptSource);
Right now as of Qt 4.4/4.5 I don't think there are any direct way, but it's coming. See http://labs.trolltech.com/blogs/2009/04/07/qwebelement-sees-the-light-do-i-hear-a-booyakasha/
the DOM manipulation via javascript method is incredibly poor. for any serious usage it very quickly becomes apparent that it is completely unusable. an experiment was made to create a runtime for pyjamas-desktop using pywebkitqt4 and it utterly, utterly failed. quite a lot was achieved - such as event callbacks written in python - but they had to be set up... by creating a javascript code-snippet! this approach is truly insane. every time you want to manipulate the DOM model from python you have to go via a crap language like javascript? anybody who thinks that's a good idea is completely off their heads.
fortunately at some point in the future i will be extending pythonwebkit to allow full access to DOM functions: it will be quite easy to do this, but i just don't have the time spare at the moment to compile up webkit for qt4 (it takes 90 mins for webkit with gtk as it is).

Is there a way to run ActiveX components in Firefox through the use of a plugin?

I have an ActiveX plugin that we need (if possible) to run in Firefox. Is there a plugin (or other way) for Firefox that will allow this?
I seem to have found a solution:
http://code.google.com/p/ff-activex-host/
"This Firefox plugin makes it possible to use ActiveX controls in Firefox. It is based on the Gecko NPAPI and provides full access to the hosted control (events, functions, properties)."
You used to be able to in Firefox 1.5 but not any longer I believe, the plugin doesnt seem to be supported anymore.
More info here
Not sure if this is helpful or not, but writing an NPAPI plugin for Firefox is fairly straightforward IMO - easier than writing an ActiveX control, so you might find it worthwhile to write one, especially as it should work in all the other browsers "for free".
This is a great example of a simple NPAPI plugin.
I found an other ActiveX plug-in that works.
It is called neptune.
See for more info http://www.meadroid.com/neptune/index.htm
You could also use firebreath, which allows you to easily create a plugin that will work on both firefox and IE; it's easy to create new methods and properties to be exposed to javascript, but you only do it in one place and it works on both browsers.
http://firebreath.googlecode.com
Yeah, I'm one of the project maintainers, so I'm biased =]