From 311a18a3075a746c7f733f270cdd24e4940fc68f Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 5 Oct 2017 22:30:46 -0400 Subject: [PATCH] add site form and autofill detection improvements --- src/background.js | 2 +- src/content/autofiller.js | 12 +++++++-- src/content/notificationBar.js | 43 ++++++++++++++++++--------------- src/services/autofillService.js | 7 +----- 4 files changed, 35 insertions(+), 29 deletions(-) diff --git a/src/background.js b/src/background.js index de4ba7c0e2..05d7ae279b 100644 --- a/src/background.js +++ b/src/background.js @@ -118,7 +118,7 @@ var bg_isBackground = true, else if (msg.command === 'collectPageDetailsResponse') { if (msg.sender === 'notificationBar') { 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') { bg_autofillService.doAutoFillForLastUsedLogin([{ diff --git a/src/content/autofiller.js b/src/content/autofiller.js index d402d83851..478ebaa915 100644 --- a/src/content/autofiller.js +++ b/src/content/autofiller.js @@ -1,11 +1,19 @@ document.addEventListener('DOMContentLoaded', function (event) { + var pageHref = null; + chrome.storage.local.get('enableAutoFillOnPageLoad', function (obj) { if (obj && obj.enableAutoFillOnPageLoad === true) { - setTimeout(fill, 500); - window.addEventListener('popstate', fill); + setInterval(doFillIfNeeded, 500); } }); + function doFillIfNeeded() { + if (pageHref !== window.location.href) { + pageHref = window.location.href; + fill(); + } + } + function fill() { chrome.runtime.sendMessage({ command: 'bgCollectPageDetails', diff --git a/src/content/notificationBar.js b/src/content/notificationBar.js index 358bf3fa5f..4fdbc9b9a3 100644 --- a/src/content/notificationBar.js +++ b/src/content/notificationBar.js @@ -1,10 +1,23 @@ document.addEventListener('DOMContentLoaded', function (event) { var pageDetails = [], formData = [], - barType = null; + barType = null, + pageHref = null; - setTimeout(collect, 1000); - window.addEventListener('popstate', collect); + if (window.location.hostname.indexOf('bitwarden.com') === -1) { + 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) { if (msg.command === 'openNotificationBar') { @@ -22,7 +35,7 @@ sendResponse(); return true; } - else if (msg.command === 'pageDetails') { + else if (msg.command === 'notificationBarPageDetails') { pageDetails.push(msg.data.details); watchForms(msg.data.forms); sendResponse(); @@ -30,22 +43,12 @@ } }); - function collect() { - if (window.location.hostname.indexOf('bitwarden.com') === -1) { - 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) { - chrome.runtime.sendMessage({ - command: 'bgCollectPageDetails', - sender: 'notificationBar' - }); - } - }); + function collectIfNeeded() { + if (pageHref !== window.location.href) { + pageHref = window.location.href; + chrome.runtime.sendMessage({ + command: 'bgCollectPageDetails', + sender: 'notificationBar' }); } } diff --git a/src/services/autofillService.js b/src/services/autofillService.js index 0c570049cd..8e52a202d8 100644 --- a/src/services/autofillService.js +++ b/src/services/autofillService.js @@ -160,12 +160,7 @@ function initAutofill() { var passwordFields = [], formData = []; - passwordFields = loadPasswordFields(pageDetails, false); - if (!passwordFields.length) { - // not able to find any viewable password fields. maybe there are some "hidden" ones? - passwordFields = loadPasswordFields(pageDetails, true); - } - + passwordFields = loadPasswordFields(pageDetails, true); if (passwordFields.length) { for (var formKey in pageDetails.forms) { for (var i = 0; i < passwordFields.length; i++) {