diff --git a/client/lib/AwaitedEventTarget.ts b/client/lib/AwaitedEventTarget.ts index 2aba92620..5f28f8d8b 100644 --- a/client/lib/AwaitedEventTarget.ts +++ b/client/lib/AwaitedEventTarget.ts @@ -14,7 +14,9 @@ export default class AwaitedEventTarget implements IAwaitedEventTarget { options?, ): Promise { const { target, jsPath } = await this.getEventTarget(); - return (await target).addEventListener(jsPath, eventType as string, listenerFn as any, options); + const awaitedTarget = await target; + if (!awaitedTarget) return; + return awaitedTarget.addEventListener(jsPath, eventType as string, listenerFn as any, options); } public async removeEventListener( @@ -22,7 +24,9 @@ export default class AwaitedEventTarget implements IAwaitedEventTarget { listenerFn: T[K] & Function, ): Promise { const { target, jsPath } = await this.getEventTarget(); - return (await target).removeEventListener(jsPath, eventType as string, listenerFn as any); + const awaitedTarget = await target; + if (!awaitedTarget) return; + return awaitedTarget.removeEventListener(jsPath, eventType as string, listenerFn as any); } // aliases