From 2fd83f830db77960367b2ddbf427bb9fed97e74f Mon Sep 17 00:00:00 2001 From: Jakub Gilis Date: Fri, 11 Apr 2025 21:30:06 +0200 Subject: [PATCH] Properly handle message aborts during cleanup (#13841) Replace the FallbackRequestedError rejection pattern with direct AbortController.abort() calls when destroying the Messenger. This eliminates misleading console errors and ensures correct cancellation behavior. The FallbackRequestedError is intended specifically for user-requested WebAuthn fallbacks, not general message cleanup operations. Fixes GitHub issue #12663 --- .../autofill/fido2/content/messaging/messenger.ts | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/apps/browser/src/autofill/fido2/content/messaging/messenger.ts b/apps/browser/src/autofill/fido2/content/messaging/messenger.ts index a5530d87a8e..ec7ff3bb7a4 100644 --- a/apps/browser/src/autofill/fido2/content/messaging/messenger.ts +++ b/apps/browser/src/autofill/fido2/content/messaging/messenger.ts @@ -1,7 +1,5 @@ // FIXME: Update this file to be type safe and remove this and next line // @ts-strict-ignore -import { FallbackRequestedError } from "@bitwarden/common/platform/abstractions/fido2/fido2-client.service.abstraction"; - import { Message, MessageType } from "./message"; const SENDER = "bitwarden-webauthn"; @@ -126,17 +124,11 @@ export class Messenger { } }; - let onDestroyListener; - const destroyPromise: Promise = new Promise((_, reject) => { - onDestroyListener = () => reject(new FallbackRequestedError()); - this.onDestroy.addEventListener("destroy", onDestroyListener); - }); + const onDestroyListener = () => abortController.abort(); + this.onDestroy.addEventListener("destroy", onDestroyListener); try { - const handlerResponse = await Promise.race([ - this.handler(message, abortController), - destroyPromise, - ]); + const handlerResponse = await this.handler(message, abortController); port.postMessage({ ...handlerResponse, SENDER }); } catch (error) { port.postMessage({