mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 08:13:42 +00:00
[PM-8027] Updating how we guard against excessive getPageDetails calls
This commit is contained in:
@@ -44,7 +44,7 @@ class CollectAutofillContentService implements CollectAutofillContentServiceInte
|
|||||||
private elementInitializingIntersectionObserver: Set<Element> = new Set();
|
private elementInitializingIntersectionObserver: Set<Element> = new Set();
|
||||||
private mutationObserver: MutationObserver;
|
private mutationObserver: MutationObserver;
|
||||||
private mutationsQueue: MutationRecord[][] = [];
|
private mutationsQueue: MutationRecord[][] = [];
|
||||||
private currentlyUpdatingPageDetails = false;
|
private updateAfterMutationIdleCallback: number;
|
||||||
private readonly updateAfterMutationTimeout = 1000;
|
private readonly updateAfterMutationTimeout = 1000;
|
||||||
private readonly formFieldQueryString;
|
private readonly formFieldQueryString;
|
||||||
private readonly nonInputFormFieldTags = new Set(["textarea", "select"]);
|
private readonly nonInputFormFieldTags = new Set(["textarea", "select"]);
|
||||||
@@ -1223,19 +1223,13 @@ class CollectAutofillContentService implements CollectAutofillContentServiceInte
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
private updateAutofillElementsAfterMutation() {
|
private updateAutofillElementsAfterMutation() {
|
||||||
if (this.currentlyUpdatingPageDetails) {
|
if (this.updateAfterMutationIdleCallback) {
|
||||||
return;
|
globalThis.cancelIdleCallback(this.updateAfterMutationIdleCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.currentlyUpdatingPageDetails = true;
|
this.updateAfterMutationIdleCallback = globalThis.requestIdleCallback(
|
||||||
globalThis.requestIdleCallback(
|
this.getPageDetails.bind(this),
|
||||||
async () => {
|
{ timeout: this.updateAfterMutationTimeout },
|
||||||
await this.getPageDetails();
|
|
||||||
this.currentlyUpdatingPageDetails = false;
|
|
||||||
},
|
|
||||||
{
|
|
||||||
timeout: this.updateAfterMutationTimeout,
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1457,6 +1451,9 @@ class CollectAutofillContentService implements CollectAutofillContentServiceInte
|
|||||||
* timeouts and disconnects the mutation observer.
|
* timeouts and disconnects the mutation observer.
|
||||||
*/
|
*/
|
||||||
destroy() {
|
destroy() {
|
||||||
|
if (this.updateAfterMutationIdleCallback) {
|
||||||
|
globalThis.cancelIdleCallback(this.updateAfterMutationIdleCallback);
|
||||||
|
}
|
||||||
this.mutationObserver?.disconnect();
|
this.mutationObserver?.disconnect();
|
||||||
this.intersectionObserver?.disconnect();
|
this.intersectionObserver?.disconnect();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user