Skip to content

Commit

Permalink
[PM-8869] Fix broken autofill cache invalidation features on Safari (#…
Browse files Browse the repository at this point in the history
…9643)

* [PM-8869] Autofill features broken on Safari

* [PM-8869] Autofill features broken on Safari
  • Loading branch information
cagonzalezcs authored and differsthecat committed Jun 24, 2024
1 parent 71aa346 commit b829d36
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
nodeIsFormElement,
nodeIsInputElement,
// sendExtensionMessage,
requestIdleCallbackPolyfill,
} from "../utils";

import { AutofillOverlayContentService } from "./abstractions/autofill-overlay-content.service";
Expand Down Expand Up @@ -1057,7 +1058,7 @@ class CollectAutofillContentService implements CollectAutofillContentServiceInte
}

if (!this.mutationsQueue.length) {
globalThis.requestIdleCallback(this.processMutations, { timeout: 500 });
requestIdleCallbackPolyfill(this.processMutations, { timeout: 500 });
}
this.mutationsQueue.push(mutations);
};
Expand Down Expand Up @@ -1194,7 +1195,7 @@ class CollectAutofillContentService implements CollectAutofillContentServiceInte
continue;
}

globalThis.requestIdleCallback(
requestIdleCallbackPolyfill(
// We are setting this item to a -1 index because we do not know its position in the DOM.
// This value should be updated with the next call to collect page details.
() => void this.buildAutofillFieldItem(node as ElementWithOpId<FormFieldElement>, -1),
Expand Down
14 changes: 14 additions & 0 deletions apps/browser/src/autofill/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
import { AutofillPort } from "../enums/autofill-port.enums";
import { FillableFormFieldElement, FormFieldElement } from "../types";

/**
* Polyfills the requestIdleCallback API with a setTimeout fallback.
*
* @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>) {
if ("requestIdleCallback" in globalThis) {
return globalThis.requestIdleCallback(() => callback(), options);
}

return globalThis.setTimeout(() => callback(), 1);
}

/**
* Generates a random string of characters that formatted as a custom element name.
*/
Expand Down

0 comments on commit b829d36

Please sign in to comment.