fix autofill: handle two-step login forms (CommuniGate)

- Fill username by specific attrs even without visible password field
  (handles two-step forms: username first, password appears after)
- Broad input[type=text] fallback only fires when password field is present
  (prevents filling R7-Office font selector and other app inputs)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-07-21 11:02:55 +00:00
parent d258f3e0fd
commit de56959ba2
+27 -12
View File
@@ -115,24 +115,39 @@ _AUTOFILL_CONTENT_JS = r"""
function tryFill() { function tryFill() {
const p = findPassField(); const p = findPassField();
// No visible password field = not a login form; stop to avoid filling app inputs
if (!p) return; // Fill by specific attrs even on two-step forms (where password isn't visible yet)
const u = findUserField(p); const uSpec = findUserFieldByAttrs();
// Fill login FIRST so password-triggered re-render doesn't clear it if (CREDS.login && uSpec) {
if (CREDS.login && u) { if (setNativeValue(uSpec, CREDS.login)) {
if (setNativeValue(u, CREDS.login)) { console.log('[PortalAutofill] user filled (specific)');
console.log('[PortalAutofill] user filled');
} }
} }
if (CREDS.password && p) {
// Without a visible password field don't use broad fallback —
// prevents filling generic app inputs (e.g. R7-Office font selector)
if (!p) return;
// With password field: also try proximity / broad fallback for username
const u = uSpec || findUserFieldNearPassword(p) ||
Array.from(document.querySelectorAll('input[type="text"], input:not([type])'))
.find(isVisible) || null;
if (CREDS.login && u && u !== uSpec) {
if (setNativeValue(u, CREDS.login)) {
console.log('[PortalAutofill] user filled (fallback)');
}
}
if (CREDS.password) {
if (setNativeValue(p, CREDS.password)) { if (setNativeValue(p, CREDS.password)) {
console.log('[PortalAutofill] password filled'); console.log('[PortalAutofill] password filled');
} }
} }
// Some apps (e.g. Zabbix) clear username after password events — re-fill if needed // Re-fill guard: some apps clear username after password events
if (CREDS.login && u && u.value !== CREDS.login) { const uFinal = u || uSpec;
setNativeValue(u, CREDS.login); if (CREDS.login && uFinal && uFinal.value !== CREDS.login) {
console.log('[PortalAutofill] user re-filled after password'); setNativeValue(uFinal, CREDS.login);
console.log('[PortalAutofill] user re-filled');
} }
} }