Autofill logins in Chrome using AccessibilityService Android

1.3k views Asked by At

I am developing an application that requires to auto-fill logins in other installed apps and chrome. I am able to successfully auto-fill logins in other installed apps using AccessibilityService but could not get it working on Chrome browser. I am able to identify the username and password AccessibilityNodeInfo but I am not able to paste the content into it.

This is how I am trying, I am copying the content to be filled into Clipboard and then pasting the content into these username and password fields using AccessibilityNodeInfo.ACTION_PASTE. This technique works well for other installed apps but it fails to paste in Chrome. I am not able to find any relevant posts online except this one - link, but there is no clear solution in it. Also I am not able to find anything documented on developer site too. Should I be injecting javascript code to paste my content? If so can you please give me an example? I have done that using WebView previously but in this case I don't have reference to the view.

Any help on this will be greatly appreciated.

3

There are 3 answers

0
j_mcnally On

You can run javascript to accomplish this by executing something like the following:

document.getElementById("username").val = "username";

however I doubt if you can just run arbitary js in the chrome app as an outside app.

0
Murtaza Khursheed Hussain On

Well Google doesn't allow that

"You can't use an AccessibilityService to inject JavaScript"

"There are no plans to support javascript extensions or any other method of injecting javascript in Chrome or a WebView."

You can read more here...

0
Prasad Pawar On

You can use this method to accomplish the autofill:

private void setNodeText(AccessibilityNodeInfo node, String str) {
        Bundle bundle = new Bundle();
        bundle.putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, str);
        node.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, bundle);
}