Skip to content

LiveV2Session raises uncatchable InvalidAccessError on session destroy in browser/Electron #42

Description

@egenthon-cmd

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.tsWebSocketSession.close() and internal close handling
  • packages/sdk-js/src/v2/live/session.ts — abort listener calling webSocketSession.close(1001, 'Aborted')

Steps to reproduce

  1. Open a Live V2 session in a browser or Electron app
  2. Call endSession() (or equivalent destroy flow)
  3. 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

  1. 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).

  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions