RoelVB / ChromeKeePass

Chrome extensions for automatically filling credentials from KeePass/KeeWeb

Home Page:https://chrome.google.com/webstore/detail/chromekeepass/dphoaaiomekdhacmfoblfblmncpnbahm

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Login input detection

btxtiger opened this issue · comments

I actually didn't find yet how the login input field detection works. I would be open to contribute some improvements.
There are a couple of sites, where the login field is not recognized, especially if it is behind a modal.

You can comment more, if you have the issue.

commented

Sometime you have to "redetect fields" using the right-click menu or the keyboardshortcut.
I've tested this with Instagram and Twitter and it works fine.

I appreciate you wanting to contribute. This is how the detection flow is now:
The content_script calls the detectFields() method after the page is loaded:

$(document).ready(()=>{
pageControl.detectFields();
});

Then the PageControl class tries to find credential fields:

public detectFields()
{
const fieldSets: FieldSet[] = [];
let passwordFields: JQuery<HTMLElement> = $('input[type="password"]');
if(passwordFields.length) // Found some password fields?
{
passwordFields.each((passwordIndex, passwordField)=>{ // Loop through password fields
let prevField: JQuery<HTMLElement>;
$('input').each((inputIndex, input)=>{ // Loop through input fields to find the field before our password field
const inputType = $(input).attr('type') || 'text'; // Get input type, if none default to "text"
if(inputType != 'password') // We didn't reach our password field?
{
if($(input).is(':visible') && (inputType === 'text' || inputType === 'email' || inputType === 'tel')) // Is this a possible username field?
prevField = $(input);
}
else if($(input).is($(passwordField))) // Found our password field?
{
if(prevField) // Is there a previous field? Than this should be our username field
{
fieldSets.push(new FieldSet(this, $(passwordField), prevField));
return; // Break the each() loop
}
else if($(input).is(':visible')) // We didn't find the username field. Check if it's actually visible
{
fieldSets.push(new FieldSet(this, $(passwordField)));
return; // Break the each() loop
}
else // We didn't find a visible username of password field
return;
}
});
});
}
// Remember the fields we've found
this._fieldSets = fieldSets;
this._findCredentials();
this._attachEscapeEvent();
}