keepassxreboot / keepassxc-browser

KeePassXC Browser Extension
GNU General Public License v3.0
1.78k stars 188 forks source link

Allow scripting of autofill #720

Open tremby opened 4 years ago

tremby commented 4 years ago

Expected Behavior

I'd like to be able to script autofill. I want to be able to specify, with a bit of JS code if necessary, which fields should be filled with which "additional attributes" present in the entry, so that when the page is autofilled the right things go in the right places.

Current Behavior

Some websites (one of my banks for example) have extra fields which need to be entered. I know of the "string fields" feature, but the fields aren't always the same or in the same order (such as security questions) and aren't always on the same page (security question on one page, password on the next), and the "string fields" only let custom fields be filled in a specific order. Basing things on order also seems somewhat brittle to me.

At the moment, on my bank website's security question page, it asks me one of my security questions at random, and the field is of type password so it gets autofilled with my password, which isn't correct in this context. I correct it manually, then on the next page my password gets autofilled correctly.

I'm aware of the workaround of adding extra entries for each particular form. I don't like this workaround, since it distributes related data in my database.

Possible Solution

390 would help, since I could click the field in question and select the relevant question from the list, but it'd like much more if this were automatic.

I'd like if there were some scheme for "additional attributes" which would target them to fields with specific names or IDs or with specific labels. I'm a web developer and so know CSS selectors and JS, and it seems to me doing this by CSS selector would be a nice way to do it, or using JS if it's too complicated for a simple query.

By CSS selector

These attributes might put their value into the first matching element found on the page:

These could be done simply with document.querySelector(attributeName.replace(/^Selector:\s*/i, '')).value = attributeValue, though with a check to see if a matching element was actually found.

By JS function

Some fields (my bank's security question for example) can't be selected with a simple CSS selector, since I need to know the contents of a text node to know if it matches. CSS can't select based on that. So I'd like to also be able to use some JS to select an element.

Perhaps we give a function which would return the element, given the parameter which is the root node being searched (like document). If null or undefined are returned the value wouldn't get filled anywhere. Examples:

Shorthands

Maybe shorthands to some of the most common forms could be available:

Other thoughts:

Discussion

Would this be a desirable feature? Likely to be merged if it works well?

I'd be potentially interested in having a go at implementing it if so. Before doing so I'd want to discuss and make sure I'm on the same page about featureset and direction.

varjolintu commented 4 years ago

I assume you have already tried using String Fields with Choose Custom login fields for this page? That would do exactly the thing you are proposing.

EDIT: The issue you linked has a comment about it: https://github.com/keepassxreboot/keepassxc-browser/issues/390#issuecomment-457808066

tremby commented 4 years ago

That won't work because, exactly like in the comment following the one you just linked, each time I visit the page the fields are different and need different responses.

varjolintu commented 4 years ago

I see. The attribute filling should be much simpler feature to make. This kind of scripting is a major feature and it would take a lot of time to implement and test.