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:
@@ -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) => {
|
this.onDestroy.addEventListener("destroy", onDestroyListener);
|
||||||
onDestroyListener = () => reject(new FallbackRequestedError());
|
|
||||||
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({
|
||||||
|
|||||||
Reference in New Issue
Block a user