1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-11 05:43:41 +00:00

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
This commit is contained in:
Jakub Gilis
2025-04-11 21:30:06 +02:00
committed by GitHub
parent d5b7af75e9
commit 2fd83f830d

View File

@@ -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<never> = 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({