1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-18 15:47:57 +01:00

add site form and autofill detection improvements

This commit is contained in:
Kyle Spearrin 2017-10-05 22:30:46 -04:00
parent 2a929c8de8
commit 311a18a307
4 changed files with 35 additions and 29 deletions

View File

@ -118,7 +118,7 @@ var bg_isBackground = true,
else if (msg.command === 'collectPageDetailsResponse') { else if (msg.command === 'collectPageDetailsResponse') {
if (msg.sender === 'notificationBar') { if (msg.sender === 'notificationBar') {
var forms = bg_autofillService.getFormsWithPasswordFields(msg.details); var forms = bg_autofillService.getFormsWithPasswordFields(msg.details);
messageTab(msg.tab.id, 'pageDetails', { details: msg.details, forms: forms }); messageTab(msg.tab.id, 'notificationBarPageDetails', { details: msg.details, forms: forms });
} }
else if (msg.sender === 'autofiller' || msg.sender === 'autofill_cmd') { else if (msg.sender === 'autofiller' || msg.sender === 'autofill_cmd') {
bg_autofillService.doAutoFillForLastUsedLogin([{ bg_autofillService.doAutoFillForLastUsedLogin([{

View File

@ -1,11 +1,19 @@
document.addEventListener('DOMContentLoaded', function (event) { document.addEventListener('DOMContentLoaded', function (event) {
var pageHref = null;
chrome.storage.local.get('enableAutoFillOnPageLoad', function (obj) { chrome.storage.local.get('enableAutoFillOnPageLoad', function (obj) {
if (obj && obj.enableAutoFillOnPageLoad === true) { if (obj && obj.enableAutoFillOnPageLoad === true) {
setTimeout(fill, 500); setInterval(doFillIfNeeded, 500);
window.addEventListener('popstate', fill);
} }
}); });
function doFillIfNeeded() {
if (pageHref !== window.location.href) {
pageHref = window.location.href;
fill();
}
}
function fill() { function fill() {
chrome.runtime.sendMessage({ chrome.runtime.sendMessage({
command: 'bgCollectPageDetails', command: 'bgCollectPageDetails',

View File

@ -1,10 +1,23 @@
document.addEventListener('DOMContentLoaded', function (event) { document.addEventListener('DOMContentLoaded', function (event) {
var pageDetails = [], var pageDetails = [],
formData = [], formData = [],
barType = null; barType = null,
pageHref = null;
setTimeout(collect, 1000); if (window.location.hostname.indexOf('bitwarden.com') === -1) {
window.addEventListener('popstate', collect); chrome.storage.local.get('neverDomains', function (obj) {
var domains = obj.neverDomains;
if (domains && domains.hasOwnProperty(window.location.hostname)) {
return;
}
chrome.storage.local.get('disableAddLoginNotification', function (obj) {
if (!obj || !obj.disableAddLoginNotification) {
setInterval(collectIfNeeded, 1000);
}
});
});
}
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) { chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
if (msg.command === 'openNotificationBar') { if (msg.command === 'openNotificationBar') {
@ -22,7 +35,7 @@
sendResponse(); sendResponse();
return true; return true;
} }
else if (msg.command === 'pageDetails') { else if (msg.command === 'notificationBarPageDetails') {
pageDetails.push(msg.data.details); pageDetails.push(msg.data.details);
watchForms(msg.data.forms); watchForms(msg.data.forms);
sendResponse(); sendResponse();
@ -30,22 +43,12 @@
} }
}); });
function collect() { function collectIfNeeded() {
if (window.location.hostname.indexOf('bitwarden.com') === -1) { if (pageHref !== window.location.href) {
chrome.storage.local.get('neverDomains', function (obj) { pageHref = window.location.href;
var domains = obj.neverDomains; chrome.runtime.sendMessage({
if (domains && domains.hasOwnProperty(window.location.hostname)) { command: 'bgCollectPageDetails',
return; sender: 'notificationBar'
}
chrome.storage.local.get('disableAddLoginNotification', function (obj) {
if (!obj || !obj.disableAddLoginNotification) {
chrome.runtime.sendMessage({
command: 'bgCollectPageDetails',
sender: 'notificationBar'
});
}
});
}); });
} }
} }

View File

@ -160,12 +160,7 @@ function initAutofill() {
var passwordFields = [], var passwordFields = [],
formData = []; formData = [];
passwordFields = loadPasswordFields(pageDetails, false); passwordFields = loadPasswordFields(pageDetails, true);
if (!passwordFields.length) {
// not able to find any viewable password fields. maybe there are some "hidden" ones?
passwordFields = loadPasswordFields(pageDetails, true);
}
if (passwordFields.length) { if (passwordFields.length) {
for (var formKey in pageDetails.forms) { for (var formKey in pageDetails.forms) {
for (var i = 0; i < passwordFields.length; i++) { for (var i = 0; i < passwordFields.length; i++) {