fix(sync): Use requestAnimationFrame to ensure event handler is attached before event

Because:
* Android responds immediately to the can_link_account message and we don't appear to always have the event listener attached

This fix:
* Adds requestAnimationFrame, as we have needed to use this a couple of times before for testing when the response back was immediate

fixes FXA-10057
This commit is contained in:
Lauren Zugai 2024-07-11 10:18:00 -05:00
Родитель 7914defaeb
Коммит 8a46dfffe6
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 0C86B71E24811D10
1 изменённых файлов: 5 добавлений и 1 удалений

Просмотреть файл

@ -360,7 +360,11 @@ export class Firefox extends EventTarget {
resolve(detail.message?.data as FxACanLinkAccountResponse);
};
window.addEventListener('WebChannelMessageToContent', eventHandler);
this.send(FirefoxCommand.CanLinkAccount, options);
// requestAnimationFrame ensures the event listener is added first
// otherwise, there is a race condition
requestAnimationFrame(() => {
this.send(FirefoxCommand.CanLinkAccount, options);
});
});
}