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

[PM-5189] Fixing an issue found within Safari

This commit is contained in:
Cesar Gonzalez
2024-06-14 10:14:27 -05:00
parent 09f69e774c
commit 70d00a59ce
2 changed files with 17 additions and 5 deletions

View File

@@ -22,6 +22,7 @@ import {
nodeIsInputElement, nodeIsInputElement,
sendExtensionMessage, sendExtensionMessage,
requestIdleCallbackPolyfill, requestIdleCallbackPolyfill,
cancelIdleCallbackPolyfill,
} from "../utils"; } from "../utils";
import { AutofillOverlayContentService } from "./abstractions/autofill-overlay-content.service"; import { AutofillOverlayContentService } from "./abstractions/autofill-overlay-content.service";
@@ -45,7 +46,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 updateAfterMutationIdleCallback: number; private updateAfterMutationIdleCallback: NodeJS.Timeout | 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"]);
@@ -1228,10 +1229,10 @@ class CollectAutofillContentService implements CollectAutofillContentServiceInte
*/ */
private updateAutofillElementsAfterMutation() { private updateAutofillElementsAfterMutation() {
if (this.updateAfterMutationIdleCallback) { if (this.updateAfterMutationIdleCallback) {
globalThis.cancelIdleCallback(this.updateAfterMutationIdleCallback); cancelIdleCallbackPolyfill(this.updateAfterMutationIdleCallback);
} }
this.updateAfterMutationIdleCallback = globalThis.requestIdleCallback( this.updateAfterMutationIdleCallback = requestIdleCallbackPolyfill(
this.getPageDetails.bind(this), this.getPageDetails.bind(this),
{ timeout: this.updateAfterMutationTimeout }, { timeout: this.updateAfterMutationTimeout },
); );
@@ -1480,7 +1481,7 @@ class CollectAutofillContentService implements CollectAutofillContentServiceInte
*/ */
destroy() { destroy() {
if (this.updateAfterMutationIdleCallback) { if (this.updateAfterMutationIdleCallback) {
globalThis.cancelIdleCallback(this.updateAfterMutationIdleCallback); cancelIdleCallbackPolyfill(this.updateAfterMutationIdleCallback);
} }
this.mutationObserver?.disconnect(); this.mutationObserver?.disconnect();
this.intersectionObserver?.disconnect(); this.intersectionObserver?.disconnect();

View File

@@ -7,7 +7,10 @@ import { FillableFormFieldElement, FormFieldElement } from "../types";
* @param callback - The callback function to run when the browser is idle. * @param callback - The callback function to run when the browser is idle.
* @param options - The options to pass to the requestIdleCallback function. * @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) { if ("requestIdleCallback" in globalThis) {
return globalThis.requestIdleCallback(() => callback(), options); return globalThis.requestIdleCallback(() => callback(), options);
} }
@@ -15,6 +18,14 @@ export function requestIdleCallbackPolyfill(callback: () => void, options?: Reco
return globalThis.setTimeout(() => callback(), 1); 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. * Generates a random string of characters that formatted as a custom element name.
*/ */