1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-28 04:08:47 +02:00

Ability to auto-fill span elements (#2095)

* ability to autofill span elements

* add modification comments
This commit is contained in:
Kyle Spearrin 2021-09-30 16:02:13 -04:00 committed by GitHub
parent 1619fe533e
commit 812741219d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 65 additions and 5 deletions

View File

@ -26,6 +26,10 @@
} }
} }
span[data-bwautofill].com-bitwarden-browser-animated-fill {
display: inline-block;
}
.com-bitwarden-browser-animated-fill { .com-bitwarden-browser-animated-fill {
animation: bitwardenfill 200ms ease-in-out 0ms 1; animation: bitwardenfill 200ms ease-in-out 0ms 1;
-webkit-animation: bitwardenfill 200ms ease-in-out 0ms 1; -webkit-animation: bitwardenfill 200ms ease-in-out 0ms 1;

View File

@ -38,6 +38,7 @@
5. Remove fakeTested prop. 5. Remove fakeTested prop.
6. Rename com.agilebits.* stuff to com.bitwarden.* 6. Rename com.agilebits.* stuff to com.bitwarden.*
7. Remove "some useful globals" on window 7. Remove "some useful globals" on window
8. Add ability to autofill span[data-bwautofill] elements
*/ */
function collect(document, undefined) { function collect(document, undefined) {
@ -103,6 +104,11 @@
return el; return el;
default: default:
// START MODIFICATION
if (!el.type && el.tagName.toLowerCase() === 'span') {
return el.innerText;
}
// END MODIFICATION
return el.value; return el.value;
} }
} }
@ -268,8 +274,16 @@
addProp(field, 'htmlClass', getElementAttrValue(el, 'class')); addProp(field, 'htmlClass', getElementAttrValue(el, 'class'));
addProp(field, 'tabindex', getElementAttrValue(el, 'tabindex')); addProp(field, 'tabindex', getElementAttrValue(el, 'tabindex'));
addProp(field, 'title', getElementAttrValue(el, 'title')); addProp(field, 'title', getElementAttrValue(el, 'title'));
// START MODIFICATION // START MODIFICATION
addProp(field, 'userEdited', !!el.dataset['com.browser.browser.userEdited']); addProp(field, 'userEdited', !!el.dataset['com.browser.browser.userEdited']);
var elTagName = el.tagName.toLowerCase();
addProp(field, 'tagName', elTagName);
if (elTagName === 'span') {
return field;
}
// END MODIFICATION // END MODIFICATION
if ('hidden' != toLowerString(el.type)) { if ('hidden' != toLowerString(el.type)) {
@ -555,7 +569,8 @@
var els = []; var els = [];
try { try {
var elsList = theDoc.querySelectorAll('input:not([type="hidden"]):not([type="submit"]):not([type="reset"])' + var elsList = theDoc.querySelectorAll('input:not([type="hidden"]):not([type="submit"]):not([type="reset"])' +
':not([type="button"]):not([type="image"]):not([type="file"]):not([data-bwignore]), select'); ':not([type="button"]):not([type="image"]):not([type="file"]):not([data-bwignore]), select, ' +
'span[data-bwautofill]');
els = Array.prototype.slice.call(elsList); els = Array.prototype.slice.call(elsList);
} catch (e) { } } catch (e) { }
@ -809,6 +824,12 @@
break; break;
default: default:
el.value == op || doAllFillOperations(el, function (theEl) { el.value == op || doAllFillOperations(el, function (theEl) {
// START MODIFICATION
if (!theEl.type && theEl.tagName.toLowerCase() === 'span') {
theEl.innerText = op;
return;
}
// END MODIFICATION
theEl.value = op; theEl.value = op;
}); });
} }
@ -932,6 +953,11 @@
currentEl = currentEl === document; currentEl = currentEl === document;
} }
} }
// START MODIFICATION
if (el && !el.type && el.tagName.toLowerCase() === 'span') {
return true;
}
// END MODIFICATION
return currentEl ? -1 !== 'email text password number tel url'.split(' ').indexOf(el.type || '') : false; return currentEl ? -1 !== 'email text password number tel url'.split(' ').indexOf(el.type || '') : false;
} }
@ -942,7 +968,10 @@
return null; return null;
} }
try { try {
var elements = Array.prototype.slice.call(selectAllFromDoc('input, select, button')); // START MODIFICATION
var elements = Array.prototype.slice.call(selectAllFromDoc('input, select, button, ' +
'span[data-bwautofill]'));
// END MODIFICATION
var filteredElements = elements.filter(function (o) { var filteredElements = elements.filter(function (o) {
return o.opid == theOpId; return o.opid == theOpId;
}); });

View File

@ -21,4 +21,5 @@ export default class AutofillField {
autoCompleteType: string; autoCompleteType: string;
selectInfo: any; selectInfo: any;
maxLength: number; maxLength: number;
tagName: string;
} }

View File

@ -306,7 +306,11 @@ export default class AutofillService implements AutofillServiceInterface {
}); });
pageDetails.fields.forEach((field: any) => { pageDetails.fields.forEach((field: any) => {
if (filledFields.hasOwnProperty(field.opid) || !field.viewable) { if (filledFields.hasOwnProperty(field.opid)) {
return;
}
if (!field.viewable && field.tagName !== 'span') {
return; return;
} }
@ -459,6 +463,10 @@ export default class AutofillService implements AutofillServiceInterface {
const fillFields: { [id: string]: AutofillField; } = {}; const fillFields: { [id: string]: AutofillField; } = {};
pageDetails.fields.forEach((f: any) => { pageDetails.fields.forEach((f: any) => {
if (this.forCustomFieldsOnly(f)) {
return;
}
if (this.isExcludedType(f.type, ExcludedAutofillTypes)) { if (this.isExcludedType(f.type, ExcludedAutofillTypes)) {
return; return;
} }
@ -691,6 +699,10 @@ export default class AutofillService implements AutofillServiceInterface {
const fillFields: { [id: string]: AutofillField; } = {}; const fillFields: { [id: string]: AutofillField; } = {};
pageDetails.fields.forEach((f: any) => { pageDetails.fields.forEach((f: any) => {
if (this.forCustomFieldsOnly(f)) {
return;
}
if (this.isExcludedType(f.type, ExcludedAutofillTypes)) { if (this.isExcludedType(f.type, ExcludedAutofillTypes)) {
return; return;
} }
@ -928,6 +940,10 @@ export default class AutofillService implements AutofillServiceInterface {
mustBeEmpty: boolean, fillNewPassword: boolean) { mustBeEmpty: boolean, fillNewPassword: boolean) {
const arr: AutofillField[] = []; const arr: AutofillField[] = [];
pageDetails.fields.forEach(f => { pageDetails.fields.forEach(f => {
if (this.forCustomFieldsOnly(f)) {
return;
}
const isPassword = f.type === 'password'; const isPassword = f.type === 'password';
const valueIsLikePassword = (value: string) => { const valueIsLikePassword = (value: string) => {
if (value == null) { if (value == null) {
@ -976,6 +992,10 @@ export default class AutofillService implements AutofillServiceInterface {
let usernameField: AutofillField = null; let usernameField: AutofillField = null;
for (let i = 0; i < pageDetails.fields.length; i++) { for (let i = 0; i < pageDetails.fields.length; i++) {
const f = pageDetails.fields[i]; const f = pageDetails.fields[i];
if (this.forCustomFieldsOnly(f)) {
continue;
}
if (f.elementNumber >= passwordField.elementNumber) { if (f.elementNumber >= passwordField.elementNumber) {
break; break;
} }
@ -1152,8 +1172,14 @@ export default class AutofillService implements AutofillServiceInterface {
if (field.maxLength && value && value.length > field.maxLength) { if (field.maxLength && value && value.length > field.maxLength) {
value = value.substr(0, value.length); value = value.substr(0, value.length);
} }
fillScript.script.push(['click_on_opid', field.opid]); if (field.tagName !== 'span') {
fillScript.script.push(['focus_by_opid', field.opid]); fillScript.script.push(['click_on_opid', field.opid]);
fillScript.script.push(['focus_by_opid', field.opid]);
}
fillScript.script.push(['fill_by_opid', field.opid, value]); fillScript.script.push(['fill_by_opid', field.opid, value]);
} }
private forCustomFieldsOnly(field: AutofillField): boolean {
return field.tagName === 'span';
}
} }