🎥 Make videos programmatically with React
`@remotion/web-renderer`: Clean up HTML-in-Canvas docs and warnings
Jonny Burgera70106f74db1
diff --git a/packages/docs/docs/client-side-rendering/html-in-canvas.mdx b/packages/docs/docs/client-side-rendering/html-in-canvas.mdxnew file mode 100644index 0000000000..733793a86a--- /dev/null+++ b/packages/docs/docs/client-side-rendering/html-in-canvas.mdx@@ -0,0 +1,90 @@+---+image: /generated/articles-docs-client-side-rendering-html-in-canvas.png+crumb: 'Client-side rendering'+sidebar_label: HTML in Canvas+title: HTML in Canvas<AvailableFrom v="4.0.446" />+---++:::warning+Experimental feature - expect bugs and breaking changes at any time.+[Track progress on GitHub](https://github.com/remotion-dev/remotion/issues/5913) and discuss in the [`#web-renderer`](https://remotion.dev/discord) channel on Discord.+:::++On supported Chromium-based browsers, [`@remotion/web-renderer`](/docs/web-renderer) can optionally capture full frames using the experimental [HTML-in-Canvas](https://github.com/WICG/html-in-canvas) APIs (`CanvasRenderingContext2D.drawElementImage`, `HTMLCanvasElement.requestPaint`, and a `layoutSubtree` canvas) instead of Remotion’s built-in DOM composer. This path is often faster, but **pixels may not match** the software composer.++Enabling the option does **not** guarantee that this path runs. Remotion only uses it when the browser exposes the required APIs, setup succeeds, and capture succeeds for a given frame. Otherwise it falls back to the built-in composer without blocking the render.++## Enabling++### In code++Pass `allowHtmlInCanvas: true` to [`renderMediaOnWeb()`](/docs/web-renderer/render-media-on-web) or [`renderStillOnWeb()`](/docs/web-renderer/render-still-on-web). The default is `false` when you omit the field.++```tsx twoslash title="Example"+import {renderStillOnWeb} from '@remotion/web-renderer';++declare const composition: Parameters<typeof renderStillOnWeb>[0]['composition'];++// ---cut---+await renderStillOnWeb({+ composition,+ frame: 0,+ imageFormat: 'png',+ inputProps: {},+ allowHtmlInCanvas: true,+});+```++### In the Studio++With [client-side rendering enabled](/docs/client-side-rendering), open the render modal, go to the **Other** tab, and turn on **Allow HTML-in-Canvas**. The initial value comes from your config and CLI defaults (below).++### As the Studio default++In `remotion.config.ts`:++```ts twoslash title="remotion.config.ts"+import {Config} from '@remotion/cli/config';+// ---cut---+Config.setAllowHtmlInCanvasEnabled(true);+```++Or start Studio with the CLI flag (it overrides the config file for this value):++```bash+npx remotion studio --allow-html-in-canvas+```++See [`setAllowHtmlInCanvasEnabled()`](/docs/config#setallowhtmlincanvasenabled) and [`npx remotion studio`](/docs/cli/studio#--allow-html-in-canvas) for details. The flag description is also available as:++<Options id="allow-html-in-canvas" />++## Console messages++If the native HTML-in-Canvas path is used, Remotion logs a **warning** to the browser console (tag `@remotion/web-renderer`) so you know captures may differ from the software path. If `drawElementImage` is available but capture fails for another reason, a warning explains the fallback. If the browser does not expose `drawElementImage`, Remotion stays quiet and uses the built-in composer.++Use `logLevel: 'warn'` or a more verbose level if you do not see these messages.++## Compatibility++<CompatibilityTable+ chrome+ firefox={false}+ safari={false}+ nodejs={''}+ bun={''}+ serverlessFunctions=""+ clientSideRendering+ serverSideRendering={false}+ player={false}+ studio+ hideServers+/>++HTML-in-Canvas depends on Chromium shipping the experimental APIs (for example after enabling `chrome://flags/#canvas-draw-element` where applicable). Other browsers continue to use the built-in DOM composer.++## See also++- [How client-side rendering works](/docs/client-side-rendering/how-it-works)+- [`renderMediaOnWeb()`](/docs/web-renderer/render-media-on-web)+- [`renderStillOnWeb()`](/docs/web-renderer/render-still-on-web)diff --git a/packages/docs/docs/web-renderer/render-media-on-web.mdx b/packages/docs/docs/web-renderer/render-media-on-web.mdxindex 842a33f332..06494f2d88 100644--- a/packages/docs/docs/web-renderer/render-media-on-web.mdx+++ b/packages/docs/docs/web-renderer/render-media-on-web.mdx@@ -93,7 +93,7 @@ Specify a single frame (passing a `number`) or a range of frames (passing a tupl_number_-<Options id="scale" />+<Option id="scale" />### `allowHtmlInCanvas?`@@ -101,7 +101,7 @@ _boolean_Default `false`. In the Remotion Studio, the checkbox under **Other** is initialized from [`Config.setAllowHtmlInCanvasEnabled()`](/docs/config#setallowhtmlincanvasenabled) and the [`--allow-html-in-canvas`](/docs/cli/studio#--allow-html-in-canvas) CLI flag:-<Options id="allow-html-in-canvas" />+<Option id="allow-html-in-canvas" />When `true`, Chromium-based browsers that expose the experimental [HTML-in-Canvas](https://github.com/WICG/html-in-canvas) API (`drawElementImage`, enabled e.g. via `chrome://flags/#canvas-draw-element`) may rasterize each video frame with the browser engine instead of Remotion’s built-in DOM composer. This is usually faster but **pixels may not match** the software path.@@ -255,7 +255,7 @@ See [Cancelling renders](/docs/client-side-rendering/cancellation) for more deta_number | null_-<Options id="media-cache-size-in-bytes" />+<Option id="media-cache-size-in-bytes" />### `onArtifact?`@@ -307,7 +307,7 @@ See [Telemetry in client-side rendering](/docs/client-side-rendering/telemetry)_default `true`_-<Options id="is-production" />+<Option id="is-production" />## Return valuediff --git a/packages/docs/docs/web-renderer/render-still-on-web.mdx b/packages/docs/docs/web-renderer/render-still-on-web.mdxindex 66c9027af7..814a3be45f 100644--- a/packages/docs/docs/web-renderer/render-still-on-web.mdx+++ b/packages/docs/docs/web-renderer/render-still-on-web.mdx@@ -83,7 +83,7 @@ You cannot use [`getInputProps()`](/docs/get-input-props) to read input props in_number_-<Options id="scale" />+<Option id="scale" />### `allowHtmlInCanvas?`@@ -91,7 +91,7 @@ _boolean_Default `false`. In the Remotion Studio, the checkbox under **Other** is initialized from [`Config.setAllowHtmlInCanvasEnabled()`](/docs/config#setallowhtmlincanvasenabled) and the [`--allow-html-in-canvas`](/docs/cli/studio#--allow-html-in-canvas) CLI flag:-<Options id="allow-html-in-canvas" />+<Option id="allow-html-in-canvas" />When `true`, Chromium-based browsers that expose the experimental [HTML-in-Canvas](https://github.com/WICG/html-in-canvas) API (`drawElementImage`, enabled e.g. via `chrome://flags/#canvas-draw-element`) may rasterize the full composition frame with the browser engine instead of Remotion’s built-in DOM composer. This is usually faster but **pixels may not match** the software path.@@ -153,7 +153,7 @@ See [Cancelling renders](/docs/client-side-rendering/cancellation) for more deta_number | null_-<Options id="media-cache-size-in-bytes" />+<Option id="media-cache-size-in-bytes" />### `onArtifact?`@@ -179,7 +179,7 @@ See [Telemetry in client-side rendering](/docs/client-side-rendering/telemetry)_default `true`_-<Options id="is-production" />+<Option id="is-production" />## Return valuediff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.tsindex eff02f2f6b..3b02ca9ce3 100644--- a/packages/docs/sidebars.ts+++ b/packages/docs/sidebars.ts@@ -1066,6 +1066,7 @@ const sidebars: SidebarsConfig = {label: 'API Reference',},'client-side-rendering/how-it-works',+ 'client-side-rendering/html-in-canvas','client-side-rendering/limitations','client-side-rendering/migration','client-side-rendering/cancellation',diff --git a/packages/docs/src/components/Options.tsx b/packages/docs/src/components/Options.tsxindex fc084094b9..9ff1c8520c 100644--- a/packages/docs/src/components/Options.tsx+++ b/packages/docs/src/components/Options.tsx@@ -27,3 +27,5 @@ export const Options: React.FC<{return option.description(cli ? 'cli' : 'ssr') as JSX.Element;};++export const Option = Options;diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.tsindex d1dffe646c..93984a5bd9 100644--- a/packages/docs/src/data/articles.ts+++ b/packages/docs/src/data/articles.ts@@ -818,6 +818,15 @@ export const articles = [noAi: false,slug: 'client-side-rendering/how-it-works',},+ {+ id: 'client-side-rendering/html-in-canvas',+ title: 'HTML in Canvas<AvailableFrom v="4.0.446" />',+ relativePath: 'docs/client-side-rendering/html-in-canvas.mdx',+ compId: 'articles-docs-client-side-rendering-html-in-canvas',+ crumb: 'Client-side rendering',+ noAi: false,+ slug: 'client-side-rendering/html-in-canvas',+ },{id: 'client-side-rendering/index',title: 'Client-side rendering',diff --git a/packages/docs/src/theme/MDXComponents.js b/packages/docs/src/theme/MDXComponents.jsindex 5e2ef0613b..1df14206dd 100644--- a/packages/docs/src/theme/MDXComponents.js+++ b/packages/docs/src/theme/MDXComponents.js@@ -13,7 +13,7 @@ import {} from '../components/AvailableFrom';import {CompatibilityTable} from '../components/CompatibilityTable';import {Credits} from '../components/Credits';-import {Options} from '../components/Options';+import {Option, Options} from '../components/Options';import {SuggestedPrompts} from '../components/SuggestedPrompts';import {TsType} from '../components/TsType';import RawMarkdownCarrier from './RawMarkdownCarrier/index';@@ -29,6 +29,7 @@ export default {MinNodeVersion,MinBunVersion,Options,+ Option,Credits,YouTube,Installation,diff --git a/packages/docs/static/generated/articles-docs-client-side-rendering-html-in-canvas.png b/packages/docs/static/generated/articles-docs-client-side-rendering-html-in-canvas.pngnew file mode 100644index 0000000000..f7be13cff6Binary files /dev/null and b/packages/docs/static/generated/articles-docs-client-side-rendering-html-in-canvas.png differdiff --git a/packages/renderer/src/options/allow-html-in-canvas.tsx b/packages/renderer/src/options/allow-html-in-canvas.tsxindex 0974ac9741..0035fd3294 100644--- a/packages/renderer/src/options/allow-html-in-canvas.tsx+++ b/packages/renderer/src/options/allow-html-in-canvas.tsx@@ -11,8 +11,7 @@ export const allowHtmlInCanvasOption = {<>When client-side rendering is enabled in the Studio, allow theexperimental Chromium HTML-in-Canvas path (<code>drawElementImage</code>)- for capturing frames instead of the built-in DOM composer. Can improve- performance; pixels may differ from the software path. See{' '}+ for capturing frames instead of the built-in DOM composer. See{' '}<a href="https://www.remotion.dev/docs/web-renderer/render-media-on-web">Web Renderer docs</a>diff --git a/packages/web-renderer/src/render-media-on-web.tsx b/packages/web-renderer/src/render-media-on-web.tsxindex 8bff145821..f7f1e61cc5 100644--- a/packages/web-renderer/src/render-media-on-web.tsx+++ b/packages/web-renderer/src/render-media-on-web.tsx@@ -196,7 +196,7 @@ const internalRenderMediaOnWeb = async <if (outcome.native) {Internals.Log.warn({logLevel, tag: '@remotion/web-renderer'},- 'Using Chromium experimental HTML-in-Canvas (drawElementImage) for video frames. Pixels may differ from the built-in DOM composer. Set allowHtmlInCanvas: false to force software rasterization. See https://github.com/WICG/html-in-canvas',+ 'Using Chromium experimental HTML-in-Canvas (drawElementImage) for video frames. See https://github.com/WICG/html-in-canvas',);} else if (outcome.shouldWarn) {Internals.Log.warn(