Environment
- Runtime: Browser / Electron
- Package:
@gladiaio/sdk (JS/TS)
- Feature: Live V2 (
LiveV2Session)
Summary
LiveV2Session raises an uncatchable InvalidAccessError when destroying a session (e.g. via endSession() / destroy()).
Root cause
WebSocketSession.close() passes reserved WebSocket close codes (notably 1001 for abort and 1006 for connection errors) directly to the native WebSocket.close() call.
The browser WebSocket API only allows close codes 1000 or 3000–4999. Passing reserved codes (1001, 1005, 1006, etc.) throws InvalidAccessError.
Relevant code paths:
packages/sdk-js/src/network/wsClient.ts — WebSocketSession.close() and internal close handling
packages/sdk-js/src/v2/live/session.ts — abort listener calling webSocketSession.close(1001, 'Aborted')
Steps to reproduce
- Open a Live V2 session in a browser or Electron app
- Call
endSession() (or equivalent destroy flow)
- Observe an uncatchable
InvalidAccessError crash
Expected behavior
Session destruction completes cleanly without throwing. The caller should be able to handle teardown via endSession() / destroy() without the error bubbling to window.onerror.
Actual behavior
InvalidAccessError is thrown and cannot be caught by the caller because it originates from an abort event listener, which routes exceptions to window.onerror.
Suggested fix
-
Sanitize close codes before ws.close() — In browser environments, map reserved codes (1001, 1005, 1006, etc.) to 1000 before calling WebSocket.close(). Preserve the original reason string (e.g. "Aborted") in application-level callbacks (onclose / ended events).
-
Wrap abort listener close() in try/catch — The addEventListener('abort', …) handler in LiveV2Session should not let close failures propagate, since exceptions there are not interceptable by endSession() callers.
Labels
bug, sdk-js, live-v2, browser
Environment
@gladiaio/sdk(JS/TS)LiveV2Session)Summary
LiveV2Sessionraises an uncatchableInvalidAccessErrorwhen destroying a session (e.g. viaendSession()/destroy()).Root cause
WebSocketSession.close()passes reserved WebSocket close codes (notably 1001 for abort and 1006 for connection errors) directly to the nativeWebSocket.close()call.The browser WebSocket API only allows close codes 1000 or 3000–4999. Passing reserved codes (1001, 1005, 1006, etc.) throws
InvalidAccessError.Relevant code paths:
packages/sdk-js/src/network/wsClient.ts—WebSocketSession.close()and internal close handlingpackages/sdk-js/src/v2/live/session.ts— abort listener callingwebSocketSession.close(1001, 'Aborted')Steps to reproduce
endSession()(or equivalent destroy flow)InvalidAccessErrorcrashExpected behavior
Session destruction completes cleanly without throwing. The caller should be able to handle teardown via
endSession()/destroy()without the error bubbling towindow.onerror.Actual behavior
InvalidAccessErroris thrown and cannot be caught by the caller because it originates from anabortevent listener, which routes exceptions towindow.onerror.Suggested fix
Sanitize close codes before
ws.close()— In browser environments, map reserved codes (1001, 1005, 1006, etc.) to 1000 before callingWebSocket.close(). Preserve the original reason string (e.g."Aborted") in application-level callbacks (onclose/endedevents).Wrap abort listener
close()in try/catch — TheaddEventListener('abort', …)handler inLiveV2Sessionshould not let close failures propagate, since exceptions there are not interceptable byendSession()callers.Labels
bug,sdk-js,live-v2,browser