[webkit-dev] autocomplete/autologin functionality question

David D. Kilzer ddkilzer at kilzer.net
Wed Dec 13 04:23:43 PST 2006

I'm not a WebKit expert (nor do I play one on TV), but here's my two  

As I understand it, the autocomplete/autologin/autofill functionality  
that you see in Safari is a part of Safari, not WebKit.  That means  
that you'll have to implement this feature yourself for your own  
application.  The good news is that you may reuse the system-wide  
Keychain for usernames and passwords.  The "bad" news is that you'll  
have to come up with your own heuristics for autofilling a form.  For  
example, you must determine when a form is a login form and which  
fields need a username and password (hint: look for an <input>  
element of type="password" in a form on the page).  Note that it may  
be possible to reverse-engineer the autofill data stored in your home  
directory--probably in ~/Library/Safari/Form Data, although a quick  
look tells me that file may be encrypted.  Finally, note that sites  
using "basic" or "digest" authentication are much easier to identify  
since they're based on the HTTP protocol.

As far as doing button presses or other DOM manipulation, just  
pretend you want to do the same thing in JavaScript.  In JavaScript,  
you must get a reference to the button object in the DOM (either by  
name, or by id, or by iterating over a list of objects in a <form>),  
then you must call the click() method on the button object.  When you  
want to do the same thing from Cocoa via WebKit, the JavaScript  
interface for most objects has been "duplicated" in Objective-C!   
(That's what all the *.idl files are used for during the build--to  
generate the JavaScript interface as well as an Obj-C interface.)   
The trick is to determine the method(s) to call, and then figure out  
how to call them.  (Note that I haven't done this myself--this is  
just the way I think it works. :)

In addition to the Obj-C interface, it's also possible to take the  
JavaScript code for clicking your button, and pass that (as a string)  
to a WebKit method that will run it as if it were on the page.   
Again, I know it's possible to do, but I haven't actually written  
code to do this.  You'll need to do some more research to find out  
how.  (I think this method is slower than direct DOM manipulation,  
though, so I'd only use it as a last resort or an initial just-get-it- 
working implementation.)

Hope that helps!


On Dec 10, 2006, at 7:07 AM, Alexander Huber wrote:

> Hello all!
> first I would like to say hello - I'm a fairly 'fresh' cocoa  
> developer exploring the webkit and new to this list.
> I have a very specific question concerning autocomplete/autologin  
> functionality:
> I want to write an application (cocoa) that operates like a  
> webspider (take a given url, explore content and traverse links up  
> to a specified recursion depth) - showing up differences in the  
> content compared to my LAST exploration run.
> Now I want to login to specific sites that require authorization,  
> and I don't know how to achieve this using webkit/webview... I  
> think I somehow have to auto-fill the forms on the pages, but I  
> haven't found a solution yet.
> How do I simulate a 'button press' on a site? A search button, for  
> example, that I want to trigger after having filled a search  
> field... I know that most 'search' buttons react on pressing  
> 'enter' while the corresponding form field has the focus, but I  
> would like to be 100% sure to press a specific button on a page.
> If someone would be so kind to show me some documentation, starting  
> points, code hints or even apis I would appreciate it very much!
> Thank you all,
> Alex

More information about the webkit-dev mailing list