1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 16:23:44 +00:00

[PM-8027] Updating update of page details after mutation to act on an idle moment in the browser

This commit is contained in:
Cesar Gonzalez
2024-05-31 15:42:42 -05:00
parent 52db6775e9
commit e6848bd5eb

View File

@@ -43,9 +43,9 @@ class CollectAutofillContentService implements CollectAutofillContentServiceInte
private intersectionObserver: IntersectionObserver; private intersectionObserver: IntersectionObserver;
private elementInitializingIntersectionObserver: Set<Element> = new Set(); private elementInitializingIntersectionObserver: Set<Element> = new Set();
private mutationObserver: MutationObserver; private mutationObserver: MutationObserver;
private updateAutofillElementsAfterMutationTimeout: number | NodeJS.Timeout;
private mutationsQueue: MutationRecord[][] = []; private mutationsQueue: MutationRecord[][] = [];
private readonly updateAfterMutationTimeoutDelay = 1000; private currentlyUpdatingPageDetails = false;
private readonly updateAfterMutationTimeout = 1000;
private readonly formFieldQueryString; private readonly formFieldQueryString;
private readonly nonInputFormFieldTags = new Set(["textarea", "select"]); private readonly nonInputFormFieldTags = new Set(["textarea", "select"]);
private readonly ignoredInputTypes = new Set([ private readonly ignoredInputTypes = new Set([
@@ -1223,13 +1223,19 @@ class CollectAutofillContentService implements CollectAutofillContentServiceInte
* @private * @private
*/ */
private updateAutofillElementsAfterMutation() { private updateAutofillElementsAfterMutation() {
if (this.updateAutofillElementsAfterMutationTimeout) { if (this.currentlyUpdatingPageDetails) {
clearTimeout(this.updateAutofillElementsAfterMutationTimeout); return;
} }
this.updateAutofillElementsAfterMutationTimeout = setTimeout( this.currentlyUpdatingPageDetails = true;
this.getPageDetails.bind(this), globalThis.requestIdleCallback(
this.updateAfterMutationTimeoutDelay, async () => {
await this.getPageDetails();
this.currentlyUpdatingPageDetails = false;
},
{
timeout: this.updateAfterMutationTimeout,
},
); );
} }
@@ -1451,9 +1457,6 @@ class CollectAutofillContentService implements CollectAutofillContentServiceInte
* timeouts and disconnects the mutation observer. * timeouts and disconnects the mutation observer.
*/ */
destroy() { destroy() {
if (this.updateAutofillElementsAfterMutationTimeout) {
clearTimeout(this.updateAutofillElementsAfterMutationTimeout);
}
this.mutationObserver?.disconnect(); this.mutationObserver?.disconnect();
this.intersectionObserver?.disconnect(); this.intersectionObserver?.disconnect();
} }