[webkit-help] How to use WebKit to programmatically access DOM and call Javascript

Julien Chaffraix julien.chaffraix at gmail.com
Thu Apr 29 08:08:57 PDT 2010


Hi,

> I’ve been trying to use the WinLauncher as a starting point to manipulate
> the DOM of a web page.  There are two tests I’m trying to accomplish without
> much luck.  Both are based on the basic Google page for simplicity.

> Programmatically access the “f” form, set the “q” query value, then submit.

The Win API has the DOM bindings exposed so you should be able to do
what you want.
You need to get an IDOMDocument from your IWebFrame, then use some DOM
method to get the element you want (getElementById,
getElementsByTagName, ...). You need to cast your results to the right
type to be able to use IDOMHTMLFormElement::submit (I know no COM
magic so you will have to determine this part).

> Programmatically call Javascript to do something simple, yet visible like change the background color.

Changing CSS can be done without involving JavaScript. There are
several methods in the IWebViewPrivate (addUserScriptToGroup,
addUserStyleSheetToGroup) that are used to inject some custom
JavaScript or CSS in pages and that would be a good way to do that.

> Can anyone give me a heads up on how to best accomplish both or where I can
> find good documentation on this kind of client-side DOM manipulation?

Unfortunately there's no API documentation that I know of (maybe
someone else knows where to find it). I would say your best bet is to
look at the interfaces located here:
http://trac.webkit.org/browser/trunk/WebKit/win/Interfaces.

Hope it helps!

Regards,
Julien


More information about the webkit-help mailing list