Skip to main content

Web Renderer

Web renderer allows you to capture that output of a browser and compose it with other streams.

Overview

Web rendering is an experimental feature that lets you render websites. Furthermore, you can place other components on the website. We refer to this process as embedding.

Make sure you have a compositor version built with web renderer support. The web renderer introduces additional dependencies and significantly increases the size of the compositor binaries. To minimize that impact, we are supporting two versions of the compositor, one with web renderer support and one without it.

Embedding components

Embedding is a process of displaying child components on a website. You can define the child components in the children field of the web view. The child component IDs have to correspond to the IDs of HTML elements. The web renderer embeds the children's frames in the specified HTML elements.

Embedding methods

There are 3 embedding methods available:

  • chromium_embedding - Frames produced by child components are passed directly to a chromium instance and displayed on an HTML canvas. Passing frames to the chromium instance introduces one more copy operation on each input frame, which may cause performance problems for a large number of inputs. The HTML elements used for embedding have to be canvases.
  • native_embedding_over_content - Renders frames produced by child components on top of the website's content.
  • native_embedding_under_content - Renders frames produced by child components below the website's content. The website needs to have a transparent background. Otherwise, it will cover the frames underneath it.

You can define embedding method when registering a renderer. native_embedding_over_content is the default. For example:

await compositor.registerWebRenderer("example_website", {
url: "https://example.com",
resolution: {
width: 1920,
height: 1080
},
embeddingMethod: "chromium_embedding"
})

Example usage

Firstly, the web renderer instance has to be registered:

await compositor.registerWebRenderer("example_website", {
url: "https://example.com",
resolution: {
width: 1920,
height: 1080
},
embeddingMethod: "native_embedding_over_content"
})
  • instanceId - unique renderer identifier. After the registration, the WebView component references the web renderer using this identifier.
  • url - website url. All URL protocols supported by Chromium can be used here.

After registration you can use it by adding <WebView instanceId="example_website" /> in the scene.

warning

Only one web view component can use a specific web renderer instance at the time.


The above request defines a simple scene which displays a website. Now, we can modify that request and embed an input stream into the website:

function App() {
return (
<WebView instanceId="example_website">
<InputStream id="my_video" inputId="input_1" />
</WebView>
)
}
  • id - the ID of an HTML element.
note

The input stream has to be registered beforehand.

Web renderer places frames in HTML elements that are inside the website. Each HTML element must have an id attribute defined. Here's an example website:

<html>
<body>
<canvas id="my_video"></canvas>
</body>
</html>

Limitations

Internally, the web renderer uses Chromium Embedded Framework. To render a website, we have to copy frames between CPU and GPU memory, which can become a bottleneck. That is especially true for chromium_embedding since we have to copy frames from all children components.