Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 83
Registered: ‎06-20-2013
My Device: Blackberry 10
My Carrier: idea
Accepted Solution

autofill login credentials in webview

Helo all,

I want to programmatically autofill the username and password feilds of gmail in my webview...

Any help would be appreciable...

 

Thanks & regards

Developer
Posts: 26
Registered: ‎10-05-2013
My Device: Z10
My Carrier: ?

Re: autofill login credentials in webview

settings.credentialAutoFillEnabled: true
Developer
Posts: 83
Registered: ‎06-20-2013
My Device: Blackberry 10
My Carrier: idea

Re: autofill login credentials in webview

yes but i guess this will just allow me to autofill the webpage...but will not directly autofill te webpage through my code..

Im looking for some script to implement in my code that will directly autofill the webpage on loading...

 

Thanks

Developer
Posts: 18
Registered: ‎02-13-2014
My Device: Z10 STL-003
My Carrier: AT&T

Re: autofill login credentials in webview

One option you have is to use Javascript injection, however this is not the most secure way to handle passwords :Whistling:

 

But the results work.

 

The basic code is:

          WebView {
                id: webview
                url: "https://mail.google.com/"
                settings.webInspectorEnabled: true
                onLoadingChanged: {
                    if (title == "Gmail"){
                        var Email = "Email";
                        var Passwd = "Password"
                        var inject = "document.getElementById('Email').value = \""+Email+"\";"+
                        "document.getElementById('Passwd').value = \""+Passwd+"\";";
                        webview.evaluateJavaScript(inject);
                    }
                }
            }

 To rember the password and username I suppose you could use QSettings... but again... security. :Dots:

 

Good Luck.

Developer
Posts: 83
Registered: ‎06-20-2013
My Device: Blackberry 10
My Carrier: idea

Re: autofill login credentials in webview

cn we similarly implement autologin with the same code..That is can we directly login to the email account..

Like by finding the id of submit button and giving a click event to it

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: autofill login credentials in webview

@JoeQXS Nice answer, but there should be no problem using QSettings from a security perspective the data is saved as an ini file within your own app and cannot be accessed by anything but the app.


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 18
Registered: ‎02-13-2014
My Device: Z10 STL-003
My Carrier: AT&T

Re: autofill login credentials in webview

I was referring to how the webview would send the password to every site with 'Gmail' as the title. I'm sure there could be stricter filters, but onLoadingChange is the only way I know to send the injection on page load.

 

And yes, you can trigger the submit button with javascript as well. I'll grab the code for you later today if you want. 

Developer
Posts: 83
Registered: ‎06-20-2013
My Device: Blackberry 10
My Carrier: idea

Re: autofill login credentials in webview

ya that would be really great to get submit button code...Thanks

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: autofill login credentials in webview

Ok fair enough, thanks for the clarification.

If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 18
Registered: ‎02-13-2014
My Device: Z10 STL-003
My Carrier: AT&T

Re: autofill login credentials in webview

[ Edited ]

Sorry, long monday...

 

Here you go.

            WebView {
                id: webview
                url: "https://mail.google.com/"
                settings.webInspectorEnabled: true
                onLoadingChanged: {
                    if (title == "Gmail"){
                        var Email = "Email";
                        var Passwd = "Password"
                        var inject = "document.getElementById('Email').value = \""+Email+"\";"+
                        "document.getElementById('Passwd').value = \""+Passwd+"\";"+
                        "document.getElementById('signIn').click();";
                        webview.evaluateJavaScript(inject);
                    }
                }
            }

 Cheers :smileyhappy: