Skip to content

fix: prevent DataCloneError in postMessage serialization#152

Open
vapi-tasker[bot] wants to merge 1 commit intomainfrom
tasker/DEVREL-464-fix-dataclone-postmessage
Open

fix: prevent DataCloneError in postMessage serialization#152
vapi-tasker[bot] wants to merge 1 commit intomainfrom
tasker/DEVREL-464-fix-dataclone-postmessage

Conversation

@vapi-tasker
Copy link

@vapi-tasker vapi-tasker bot commented Feb 4, 2026

Summary

  • Fixes DataCloneError that occurs when users pass MediaStreamTrack objects as audioSource/videoSource during web call initialization
  • Adds describeMediaSource() helper to convert MediaStreamTrack objects to serializable string descriptions
  • Adds sanitizeForPostMessage() utility for general non-cloneable value handling (functions, symbols, circular refs)
  • Updates call-start-progress event metadata to use sanitized values instead of raw MediaStreamTrack objects

Problem

When a customer passes a custom MediaStreamTrack as audioSource or videoSource to the Vapi SDK, the SDK includes these objects directly in the call-start-progress event metadata. MediaStreamTrack objects cannot be cloned by the structured clone algorithm used by postMessage, causing a DataCloneError during Daily call join:

DataCloneError: Failed to execute 'postMessage' on 'Window': #<Object> could not be cloned.

Solution

Convert non-serializable values (MediaStreamTrack, functions, symbols, etc.) to descriptive strings before including them in event metadata. The actual MediaStreamTrack is still passed to Daily's createCallObject() - only the diagnostic metadata is sanitized.

Test plan

  • Added unit tests for describeMediaSource() function
  • Added unit tests for sanitizeForPostMessage() function
  • Added integration tests verifying call-start-progress events can be JSON serialized
  • All existing tests continue to pass
  • Build succeeds

Fixes DEVREL-464

Generated with Claude Code

…rack objects

When users pass MediaStreamTrack objects as audioSource or videoSource,
these were being included directly in call-start-progress event metadata.
MediaStreamTrack objects cannot be cloned by the structured clone algorithm
used by postMessage, causing DataCloneError during Daily call join.

This fix:
- Adds describeMediaSource() to convert MediaStreamTrack to serializable strings
- Adds sanitizeForPostMessage() for general non-cloneable value handling
- Updates call-start-progress events to use describeMediaSource() for metadata
- Adds comprehensive tests for serialization utilities

Fixes DEVREL-464

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants