1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-01-10 19:38:11 +01:00

[PM-8027] Updating how we guard against excessive getPageDetails calls

This commit is contained in:
Cesar Gonzalez 2024-05-31 16:31:56 -05:00
parent 1fac4e3a34
commit 820829581d
No known key found for this signature in database
GPG Key ID: 3381A5457F8CCECF

View File

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