mirror of
https://github.com/bitwarden/browser.git
synced 2024-09-27 04:03:00 +02:00
[PM-5189] Fixing an issue found within Safari
This commit is contained in:
parent
09f69e774c
commit
70d00a59ce
@ -22,6 +22,7 @@ import {
|
||||
nodeIsInputElement,
|
||||
sendExtensionMessage,
|
||||
requestIdleCallbackPolyfill,
|
||||
cancelIdleCallbackPolyfill,
|
||||
} from "../utils";
|
||||
|
||||
import { AutofillOverlayContentService } from "./abstractions/autofill-overlay-content.service";
|
||||
@ -45,7 +46,7 @@ class CollectAutofillContentService implements CollectAutofillContentServiceInte
|
||||
private elementInitializingIntersectionObserver: Set<Element> = new Set();
|
||||
private mutationObserver: MutationObserver;
|
||||
private mutationsQueue: MutationRecord[][] = [];
|
||||
private updateAfterMutationIdleCallback: number;
|
||||
private updateAfterMutationIdleCallback: NodeJS.Timeout | number;
|
||||
private readonly updateAfterMutationTimeout = 1000;
|
||||
private readonly formFieldQueryString;
|
||||
private readonly nonInputFormFieldTags = new Set(["textarea", "select"]);
|
||||
@ -1228,10 +1229,10 @@ class CollectAutofillContentService implements CollectAutofillContentServiceInte
|
||||
*/
|
||||
private updateAutofillElementsAfterMutation() {
|
||||
if (this.updateAfterMutationIdleCallback) {
|
||||
globalThis.cancelIdleCallback(this.updateAfterMutationIdleCallback);
|
||||
cancelIdleCallbackPolyfill(this.updateAfterMutationIdleCallback);
|
||||
}
|
||||
|
||||
this.updateAfterMutationIdleCallback = globalThis.requestIdleCallback(
|
||||
this.updateAfterMutationIdleCallback = requestIdleCallbackPolyfill(
|
||||
this.getPageDetails.bind(this),
|
||||
{ timeout: this.updateAfterMutationTimeout },
|
||||
);
|
||||
@ -1480,7 +1481,7 @@ class CollectAutofillContentService implements CollectAutofillContentServiceInte
|
||||
*/
|
||||
destroy() {
|
||||
if (this.updateAfterMutationIdleCallback) {
|
||||
globalThis.cancelIdleCallback(this.updateAfterMutationIdleCallback);
|
||||
cancelIdleCallbackPolyfill(this.updateAfterMutationIdleCallback);
|
||||
}
|
||||
this.mutationObserver?.disconnect();
|
||||
this.intersectionObserver?.disconnect();
|
||||
|
@ -7,7 +7,10 @@ import { FillableFormFieldElement, FormFieldElement } from "../types";
|
||||
* @param callback - The callback function to run when the browser is idle.
|
||||
* @param options - The options to pass to the requestIdleCallback function.
|
||||
*/
|
||||
export function requestIdleCallbackPolyfill(callback: () => void, options?: Record<string, any>) {
|
||||
export function requestIdleCallbackPolyfill(
|
||||
callback: () => void,
|
||||
options?: Record<string, any>,
|
||||
): number | NodeJS.Timeout {
|
||||
if ("requestIdleCallback" in globalThis) {
|
||||
return globalThis.requestIdleCallback(() => callback(), options);
|
||||
}
|
||||
@ -15,6 +18,14 @@ export function requestIdleCallbackPolyfill(callback: () => void, options?: Reco
|
||||
return globalThis.setTimeout(() => callback(), 1);
|
||||
}
|
||||
|
||||
export function cancelIdleCallbackPolyfill(id: NodeJS.Timeout | number) {
|
||||
if ("cancelIdleCallback" in globalThis) {
|
||||
return globalThis.cancelIdleCallback(id as number);
|
||||
}
|
||||
|
||||
return globalThis.clearTimeout(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a random string of characters that formatted as a custom element name.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user