From bb1c4ad743707f14dab4408a18c88577f26bfab4 Mon Sep 17 00:00:00 2001 From: dschom Date: Wed, 10 Jul 2024 14:39:53 -0700 Subject: [PATCH] bug(settings): Make sure event handler is attached before message is sent Because: - On android mobile this response for 'CanLinkAccount' comes back immediately and no pop up is displayed. - As result, we potentially have a result, and the eventHandler might not be bound. This commit: - Attach the event handler before sending the message. --- packages/fxa-settings/src/lib/channels/firefox.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/fxa-settings/src/lib/channels/firefox.ts b/packages/fxa-settings/src/lib/channels/firefox.ts index a0cbfc48d0..ec39176c74 100644 --- a/packages/fxa-settings/src/lib/channels/firefox.ts +++ b/packages/fxa-settings/src/lib/channels/firefox.ts @@ -349,8 +349,6 @@ export class Firefox extends EventTarget { async fxaCanLinkAccount( options: FxACanLinkAccount ): Promise { - this.send(FirefoxCommand.CanLinkAccount, options); - return new Promise((resolve) => { const eventHandler = (event: Event) => { const firefoxEvent = event as FirefoxEvent; @@ -362,6 +360,7 @@ export class Firefox extends EventTarget { resolve(detail.message?.data as FxACanLinkAccountResponse); }; window.addEventListener('WebChannelMessageToContent', eventHandler); + this.send(FirefoxCommand.CanLinkAccount, options); }); }