1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-11 22:03:36 +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 // FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore // @ts-strict-ignore
import { FallbackRequestedError } from "@bitwarden/common/platform/abstractions/fido2/fido2-client.service.abstraction";
import { Message, MessageType } from "./message"; import { Message, MessageType } from "./message";
const SENDER = "bitwarden-webauthn"; const SENDER = "bitwarden-webauthn";
@@ -126,17 +124,11 @@ export class Messenger {
} }
}; };
let onDestroyListener; const onDestroyListener = () => abortController.abort();
const destroyPromise: Promise<never> = new Promise((_, reject) => {
onDestroyListener = () => reject(new FallbackRequestedError());
this.onDestroy.addEventListener("destroy", onDestroyListener); this.onDestroy.addEventListener("destroy", onDestroyListener);
});
try { try {
const handlerResponse = await Promise.race([ const handlerResponse = await this.handler(message, abortController);
this.handler(message, abortController),
destroyPromise,
]);
port.postMessage({ ...handlerResponse, SENDER }); port.postMessage({ ...handlerResponse, SENDER });
} catch (error) { } catch (error) {
port.postMessage({ port.postMessage({