mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-06 09:20:43 +01:00
observe dom for notification form collection
This commit is contained in:
parent
311a18a307
commit
e5140595e6
@ -2,7 +2,9 @@
|
|||||||
var pageDetails = [],
|
var pageDetails = [],
|
||||||
formData = [],
|
formData = [],
|
||||||
barType = null,
|
barType = null,
|
||||||
pageHref = null;
|
pageHref = null,
|
||||||
|
observer = null,
|
||||||
|
domObservationCollectTimeout = null;
|
||||||
|
|
||||||
if (window.location.hostname.indexOf('bitwarden.com') === -1) {
|
if (window.location.hostname.indexOf('bitwarden.com') === -1) {
|
||||||
chrome.storage.local.get('neverDomains', function (obj) {
|
chrome.storage.local.get('neverDomains', function (obj) {
|
||||||
@ -43,15 +45,57 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function observeDom() {
|
||||||
|
var bodies = document.querySelectorAll('body');
|
||||||
|
if (bodies.length > 0) {
|
||||||
|
observer = new window.MutationObserver(function (mutations) {
|
||||||
|
var doCollect = false;
|
||||||
|
for (var i = 0; i < mutations.length; i++) {
|
||||||
|
for (var j = 0; j < mutations[i].addedNodes.length; j++) {
|
||||||
|
var forms = mutations[i].addedNodes[j].querySelectorAll('form:not([data-bitwarden-watching])');
|
||||||
|
if (forms.length) {
|
||||||
|
doCollect = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (doCollect) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (doCollect) {
|
||||||
|
if (domObservationCollectTimeout) {
|
||||||
|
clearTimeout(domObservationCollectTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
domObservationCollectTimeout = setTimeout(collect, 1000);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
observer.observe(bodies[0], { childList: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function collectIfNeeded() {
|
function collectIfNeeded() {
|
||||||
if (pageHref !== window.location.href) {
|
if (pageHref !== window.location.href) {
|
||||||
pageHref = window.location.href;
|
pageHref = window.location.href;
|
||||||
|
if (observer) {
|
||||||
|
observer.disconnect();
|
||||||
|
observer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
collect();
|
||||||
|
observeDom();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function collect() {
|
||||||
chrome.runtime.sendMessage({
|
chrome.runtime.sendMessage({
|
||||||
command: 'bgCollectPageDetails',
|
command: 'bgCollectPageDetails',
|
||||||
sender: 'notificationBar'
|
sender: 'notificationBar'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function watchForms(forms) {
|
function watchForms(forms) {
|
||||||
if (!forms || !forms.length) {
|
if (!forms || !forms.length) {
|
||||||
|
Loading…
Reference in New Issue
Block a user