Skip to main content
Apply virtual backgrounds to your video feed during calls. You can blur your background or replace it with a custom image.

Background Blur

Apply a blur effect to your background:

Custom Background Image

Set a custom image as your virtual background:
The image URL must be accessible from the user’s browser. Consider hosting images on a CDN for best performance.

Clear Virtual Background

Remove any applied virtual background:

Virtual Background Dialog

Show Dialog

Open the built-in virtual background settings dialog:

Hide Dialog

Close the virtual background dialog:

Configure the Virtual Background Picker

Use the virtualBackground session setting to control which images appear in the virtual background picker, whether users can upload their own images, and whether blur options are available. Pass it in the settings object to joinSession():
Custom image URLs must be served with CORS enabled. If an image can’t be loaded cross-origin, the effect fails to apply and the user sees a “Virtual background could not be applied” message.

Default Images

When you don’t pass images, the picker shows these built-in images: Nature, Office, Library, Home, Night Sky, and Office Lounge. To add your own images alongside the built-in ones instead of replacing them, spread DEFAULT_VIRTUAL_BACKGROUND_IMAGES into your list:

TypeScript Types

The configuration types are exported from the SDK:

Virtual Background V2 Engine

The V2 engine runs background segmentation in a dedicated Web Worker and composites frames on the GPU. Compared to the default engine, it keeps the effect running smoothly when the tab is in the background, lowers main-thread CPU usage, and produces cleaner edges. The SDK picks the best backend for the device automatically: WebGPU or WebGL where a GPU is available, and a WebAssembly fallback otherwise. Enable it with enableV2:
If V2 fails to initialize (for example, when the worker script is blocked), the SDK logs the error and automatically falls back to the default engine for the rest of the page lifetime.

Content Security Policy

If your page sets a Content Security Policy, the V2 engine requires the following directives, where <assets host> is the host serving the assets (https://cdn.cometchat.io by default, or the host of your assetsBaseUrl):

Self-Hosting Assets

By default, virtual background assets are downloaded on demand from the CometChat CDN. To serve them from your own infrastructure, host the files below in one folder and set assetsBaseUrl to that folder:
The inference worker’s file name includes a hash of its contents, and each SDK version requests one exact file name (visible in the browser’s network tab, and in the console error when the file is missing). After upgrading the SDK, check whether the worker file name changed and copy the new file if needed. Keep the old file while pages may still load the previous SDK version.

Hide Virtual Background Button

To hide the virtual background button from the control panel:

Browser Requirements

Virtual backgrounds use machine learning for background segmentation. Performance may vary based on:
  • Device processing power
  • Browser version
  • Camera resolution

Browser Compatibility

Virtual background is not supported on iOS. Every browser on iOS, including Chrome, Edge, and Brave, is required to use Apple’s WebKit engine (the same engine as Safari), which doesn’t provide the APIs needed for real-time background segmentation.
For best results, use a Chromium-based browser or Firefox on a device with adequate processing power.