@@ -10,6 +10,7 @@ import ICoreEventPayload from '@secret-agent/core-interfaces/ICoreEventPayload';
1010import IWaitForOptions from '@secret-agent/core-interfaces/IWaitForOptions' ;
1111import IAgentMeta from '@secret-agent/core-interfaces/IAgentMeta' ;
1212import Log from '@secret-agent/commons/Logger' ;
13+ import { CanceledPromiseError } from '@secret-agent/commons/interfaces/IPendingWaitEvent' ;
1314import Session from '../lib/Session' ;
1415import Tab from '../lib/Tab' ;
1516import GlobalPool from '../lib/GlobalPool' ;
@@ -38,6 +39,8 @@ export default class ConnectionToClient extends TypedEventEmitter<{
3839 // json converts args to null which breaks undefined argument handlers
3940 const args = payload . args . map ( x => ( x === null ? undefined : x ) ) ;
4041
42+ const session = meta ?. sessionId ? Session . get ( meta . sessionId ) : undefined ;
43+
4144 let data : any ;
4245 let isError = false ;
4346 try {
@@ -58,6 +61,10 @@ export default class ConnectionToClient extends TypedEventEmitter<{
5861 }
5962 }
6063 } catch ( error ) {
64+ // if we're closing, don't emit errors
65+ if ( ( this . isClosing || session ?. isClosing ) && error instanceof CanceledPromiseError ) {
66+ return ;
67+ }
6168 isError = true ;
6269 data =
6370 error instanceof Error
@@ -69,10 +76,7 @@ export default class ConnectionToClient extends TypedEventEmitter<{
6976 : new Error ( `Unknown error occurred ${ error } ` ) ;
7077 }
7178
72- let commandId : number ;
73- if ( meta ?. sessionId ) {
74- commandId = Session . get ( meta . sessionId ) ?. sessionState ?. lastCommand ?. id ;
75- }
79+ const commandId = session ?. sessionState ?. lastCommand ?. id ;
7680
7781 const response : ICoreResponsePayload = {
7882 responseId : messageId ,
0 commit comments