Header Logo

Comparing iframe Embeds vs Custom Components for Realtime Shopping Avatars in SvelteKit

Comparing iframe Embeds vs Custom Components for Realtime Shopping Avatars in SvelteKit

Compare iframe embeds vs custom SvelteKit components for realtime shopping avatars: isolation, auth, state, and session trade-offs.

Introduction


If you want a realtime shopping avatar in SvelteKit, you usually end up choosing between two very different integration models: an <iframe> embed that you can drop into a page quickly, or a custom component that talks directly to your avatar/session backend and renders the experience in your app.


They solve different problems. An iframe is the fastest path to a secure, customer-managed embed with strong isolation. A custom component gives you tighter UX control, better composition with your existing state, and more room to tune latency-sensitive behavior. The trade-off is complexity: once you own the frontend plumbing, you also own auth, session lifecycle, error handling, and cross-browser media edge cases.


By the end of this post, you should be able to decide which model fits your product, understand the technical constraints of realtime avatars in the browser, and implement the right approach in SvelteKit without guessing at the architecture.


What actually makes a realtime shopping avatar hard


A talking avatar is not “just video.” In practice, you are coordinating at least four moving parts:


  • Speech input and response generation: the user asks a question, a voice agent produces a response.

  • Streaming media transport: audio and avatar video need to arrive continuously, usually over WebRTC or a similar realtime channel.

  • Lip sync and timing: the video face has to match the audio closely enough that drift is not obvious.

  • UI state: loading, connecting, reconnecting, permissions, idle states, and end-of-session behavior all need to stay coherent.


In a shopping context, that usually means the avatar sits on a product page, answers questions about sizing or availability, and maybe hands off to checkout or a human agent. The avatar is not the whole product; it is a realtime surface embedded in a larger application.


This is why the integration choice matters. If the avatar is a loosely coupled widget, an iframe can be a great fit. If the avatar needs to react to your cart state, selected SKU, authenticated user, or in-app navigation, a custom component often wins.


Option 1: iframe embed when you want isolation and speed


An iframe is the cleanest way to put an avatar into a site when you do not want to expose backend credentials or manage media state directly in the browser. The parent page just hosts the embed; the embedded app handles its own session creation, auth boundaries, and realtime connection.


For SvelteKit, this is especially attractive when you want to ship a shopping assistant quickly without adding a server route just to broker avatar sessions. The browser never sees your API key, and you can keep the integration entirely customer-managed on the parent page side.


Why iframe embeds are attractive


  • Security boundary: API keys stay out of the browser.

  • Operational simplicity: no custom session broker in your app.

  • Isolation: your app CSS, JS, and the avatar UI do not fight each other.

  • Policy control: per-embed settings like allowed parent origins, rate limits, and custom instructions can be enforced on the embed side.


That last point matters for customer-facing deployments. If the embed is being sold as a managed feature to merchants, the isolation and allowlist model makes it much easier to reason about abuse and accidental exposure.


What the trade-offs look like


The downside is that an iframe is a boundary, not just a component. You do not get straightforward access to the avatar’s internal state from SvelteKit, and cross-window messaging becomes your integration surface if you need coordination. If the avatar should update based on cart contents, selected product variant, or signed-in customer profile, you will need an explicit message protocol between the parent page and the iframe.


That is workable, but you should treat it like any other cross-origin integration:


  1. Define a small message schema.

  2. Validate origin on both sides.

  3. Avoid leaking user data into the iframe unless necessary.

  4. Assume the embed can reconnect or reload independently of the parent page.


In other words, iframe embeds are operationally simple but architecturally “separate.” If you need deep coupling, you will feel that separation quickly.


Option 2: custom components when the avatar is part of your app


A custom Svelte component is the right answer when the avatar is not a widget but a first-class UI element. That is common in shopping flows where the assistant should know the current product, sync to session state, or respond to app-level events like “added to cart.”


With this model, the frontend usually calls your backend, your backend creates or resumes a realtime session, and the browser connects using session-specific credentials or connection metadata. The browser still streams media over realtime transport, but you control the orchestration.


Why custom components are more flexible


  • Stateful integration: easy to pass SKU, locale, cart state, or user segment.

  • Better UX composition: avatar, chat transcript, and product UI can share layout and transitions.

  • Telemetry: you can correlate avatar events with shopping analytics more easily.

  • Feature control: you can add explicit fallback modes, loading skeletons, and custom reconnect behavior.


The cost is that you own more failure modes. Realtime media is not forgiving of sloppy session handling. If your component mounts and unmounts frequently, or if navigation causes duplicate connection attempts, you can easily end up with orphaned sessions or confusing audio behavior.


A practical SvelteKit shape for a custom integration


In SvelteKit, the clean pattern is usually:


  1. Call a server endpoint from your component to create a session.

  2. Keep API keys on the server only.

  3. Return only the session data the client needs.

  4. Attach the avatar UI to that session and clean up on destroy.


Using the REST API from your server gives you that separation. The exact fields depend on the API shape in the docs, but the pattern is straightforward:


import { json } from '@sveltejs/kit';

}
import { json } from '@sveltejs/kit';

}
import { json } from '@sveltejs/kit';

}


Then your Svelte component consumes that response and connects the UI. The important point is not the exact JSON shape; it is that the browser never sees the long-lived API key, and the session lifetime is managed by your app rather than by a third-party embed.


Where iframe wins, where custom wins


A quick decision rule helps:


  • Choose an iframe if you want a drop-in avatar surface, strong isolation, minimal backend work, and a product that can tolerate a separate embedded UI.

  • Choose a custom component if the avatar must share state with your app, participate in your design system, or respond to application events in real time.


For shopping experiences specifically, iframe often fits the “assistant widget” model: the user asks a few questions, the assistant can guide them, and the page layout stays mostly independent. Custom components fit “guided commerce” flows where the assistant is embedded in the purchase journey and should behave like part of the product UI.


Another useful test: if you need your product team to adjust copy, voice, or behavior per merchant without a frontend deploy, iframe-style customer-managed configuration can be a big advantage. If you need your frontend engineers to wire the avatar into a bespoke purchase funnel, a custom component will be easier to evolve over time.


How Protoface fits in without forcing the architecture


Protoface supports both directions, which is the right posture for a platform like this. If you are using an iframe embed, the customer-managed model keeps the browser free of API keys and lets you set per-embed behavior, origin allowlists, and rate limits. If you are building a custom SvelteKit component, the REST API and Python SDK give you a server-side way to create and manage avatars and realtime sessions without moving secrets into the client.


For voice agents specifically, the LiveKit plugin route is useful when the avatar is attached to an existing agent pipeline rather than rendered as a standalone web widget. If your shopping assistant is already built on LiveKit, the avatar becomes another realtime participant in that system instead of a separate frontend concern.


If you want to explore implementation details, the docs at docs.protoface.com are the right place to start.


Implementation gotchas in SvelteKit


No matter which model you choose, there are a few SvelteKit-specific issues worth watching:


  • SSR boundaries: browser-only media code must run in the client, not during server rendering.

  • Lifecycle cleanup: disconnect sessions and stop tracks when components unmount.

  • Hydration mismatch: do not render avatar-dependent UI that changes before the client has connected.

  • Route transitions: preserve or intentionally reset session state when navigating between product pages.


If you use an iframe, these issues are mostly contained inside the embed. If you build a custom component, they are your responsibility. That is not a reason to avoid the custom route; it is just the cost of owning the integration.


Conclusion


For realtime shopping avatars in SvelteKit, the right choice usually comes down to isolation versus integration. Use an iframe when you want a secure, low-friction widget with minimal backend work. Use a custom component when the avatar needs to participate deeply in your app’s state, layout, and analytics.


As a rule of thumb: if the avatar can live as an independent surface, isolate it. If it has to feel like part of the product, integrate it directly.


Either way, keep realtime concerns explicit: session lifecycle, media cleanup, auth boundaries, and browser-only code all deserve first-class handling. If you want a concrete starting point, browse the docs, pick the integration surface that matches your architecture, and build the smallest end-to-end flow first.

Add a face to your AI.

No credit card needed.

Add a face to your AI.

No credit card needed.

Add a face to your AI.

No credit card needed.