Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 583481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:47:51+00:00 2026-05-13T14:47:51+00:00

Update: this question is bunk. Move along, nothing to see here. You can set

  • 0

Update: this question is bunk. Move along, nothing to see here. You can set the value of the password text field from either JS or ObjC. I was wrong.

I have a WebKit-based Cocoa app which loads an HTML document containing an HTML form in a WebView. The HTML form contains a password text field like:

<form name="foo">
    <input type="password" name="bar">
</form>

I’d like to set the value of this text field programmatically (from Objective-C if possible, but I’ll do whatever works).

I believe WebKit (and every other modern browser) implements a JavaScript security feature which prevents JS scripts from setting this value programmatically.

Unfortunately, it seems that the same security restriction applies to Objective-C, as I can’t seem to set the value using ObjC either. While the JS restriction is reasonable, the ObjC seems a bit unreasonable.

Is there any way to programmatically set the value of this field (short of bundling a custom WebKit in my app that has been altered to allow this)? I’m open to any suggestion.

Here’s what I’ve tried in ObjC:

DOMHTMLDocument *doc = (DOMHTMLDocument *)[webView mainFrameDocument];
DOMHTMLFormElement *formEl = (DOMHTMLFormElement *)[[doc forms] namedItem:@"foo"];
DOMHTMLInputElement *inputEl = (DOMHTMLInputElement *)[[formEl elements] namedItem:@"bar"];
[inputEl setValue:@"baz"];

this has no effect.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:47:52+00:00Added an answer on May 13, 2026 at 2:47 pm

    This should definitely work without having to jump through any hoops to do so. I just wrote a quick test app that loaded http://mail.google.com/ and signed into it fine with the following code on SnowLeopard and Leopard:

    - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
    {
        if (![[sender mainFrame] isEqual:frame])
            return;
    
        DOMHTMLFormElement *form = (DOMHTMLFormElement *)[[frame DOMDocument] getElementById:@"gaia_loginform"];
        DOMHTMLInputElement *username = (DOMHTMLInputElement *)[[form elements] namedItem:@"Email"];
        [username setValue:@"myemailacct"];
    
        DOMHTMLInputElement *password = (DOMHTMLInputElement *)[[form elements] namedItem:@"Passwd"];
        [password setValue:@"omghi"];
    
        [form submit];
    }
    

    I also have very similar code at work whose only job is to sign into website and its been working fine on Tiger for a year. In that case I do everything, including creating the WebView via code. I would also be very surprised if Safari’s autofill didn’t use very similar code to this.

    That said, I would make sure your app isn’t doing anything crazy to the WebView. Do you do any other modification the DOM anywhere else? Try doing this in a sample app like I did and see if it works there.

    Is the HTML you’re loading your own or on a remote server? Some websites include Javascript that clears out form fields on load or a second or two after to prevent autofill. Perhaps you’re running into that?

    If all else fails, make sure nothing is being logged to the WebView’s console. You can see that by opening up the web inspector or temporarily implementing the private WebUIDelegate method:

    - (void)webView:(WebView *)webView addMessageToConsole:(NSDictionary *)message;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update: this question, including the title, was rephrased, see history for details I know
Duplicate of this question . update - This is not an exact duplicate. See
UPDATE: this question is obviously obsolete (see the date). I recommend just using modern
Update: This question was an epic failure, but here's the working solution. It's based
Update: this question has been answered (see below). I'll leave it up in case
( Update: this question's main focus is to test the nothing else part) Given
Update: Please read this question in the context of design principles, elegance, expression of
The same as this question but for java Update Based on the comments and
Update: Check out this follow-up question: Gem Update on Windows - is it broken?
I think the question is pretty self explanatory. Anyone done this before? UPDATE :

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.