Registry / web-framework / cloudflare-video-element

cloudflare-video-element

JSON →
library1.3.5jsnpmunverified

The `cloudflare-video-element` package provides a custom web component that wraps the Cloudflare video player, offering an API designed to closely mirror the standard HTMLMediaElement. Currently stable at version 1.3.5, this package is part of the `@muxinc/media-elements` monorepo, which sees frequent updates across its various media element packages, though direct updates to `cloudflare-video-element` specifically might be less frequent. Its primary differentiator is providing a familiar `<video>` tag-like interface for Cloudflare streams, promoting reusability and encapsulation within modern web applications. It also boasts seamless integration with `Media Chrome` for consistent player UI, and ships with TypeScript types for enhanced developer experience. Developers can use it directly in HTML after a simple JavaScript import, benefiting from standard browser events and properties.

npm install cloudflare-video-element
INSTALL
IMPORT
SIG · CLOUDFLARE-VIDEO-E
C
cloudflare-video-element
web-frameworkjavascriptv1.3.5
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

cloudflare-video-element
import 'cloudflare-video-element';
const CloudflareVideoElement = require('cloudflare-video-element');
This is a side-effect import that registers the `<cloudflare-video>` custom element with the browser. It does not export a named class for direct instantiation. Ensure this script runs before your custom element is rendered in the DOM.
CloudflareVideoElement (type)
import type { CloudflareVideoElement } from 'cloudflare-video-element';
import { CloudflareVideoElement } from 'cloudflare-video-element';
While the custom element is registered via a side-effect import, you can import its TypeScript type for better type checking when interacting with the element programmatically via `document.querySelector<CloudflareVideoElement>('cloudflare-video')`.

This quickstart demonstrates how to include and use the `<cloudflare-video>` custom element in an HTML page, both declaratively and with basic programmatic control using JavaScript, mimicking the standard HTMLMediaElement API.

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Cloudflare Video Element Quickstart</title> <!-- Load from CDN (or bundle your npm import) --> <script type="module" src="https://cdn.jsdelivr.net/npm/cloudflare-video-element@latest/+esm"></script> <style> cloudflare-video { width: 100%; max-width: 640px; display: block; /* Custom elements are inline by default */ margin: 20px auto; border: 1px solid #ccc; background-color: #000; } </style> </head> <body> <h1>Cloudflare Video Element Demo</h1> <p>This demonstrates the <code>&lt;cloudflare-video&gt;</code> custom element playing a Cloudflare stream, with standard HTMLMediaElement controls and API.</p> <cloudflare-video controls autoplay muted loop src="https://watch.videodelivery.net/bfbd585059e33391d67b0f1d15fe6ea4" style="--media-accent-color: #007bff;" ></cloudflare-video> <p>Programmatic control example:</p> <button id="playButton">Play</button> <button id="pauseButton">Pause</button> <button id="muteButton">Toggle Mute</button> <span id="currentTime">0:00</span> / <span id="duration">0:00</span> <script type="module"> const videoElement = document.querySelector('cloudflare-video'); const playButton = document.getElementById('playButton'); const pauseButton = document.getElementById('pauseButton'); const muteButton = document.getElementById('muteButton'); const currentTimeSpan = document.getElementById('currentTime'); const durationSpan = document.getElementById('duration'); if (videoElement) { playButton.addEventListener('click', () => videoElement.play()); pauseButton.addEventListener('click', () => videoElement.pause()); muteButton.addEventListener('click', () => videoElement.muted = !videoElement.muted); videoElement.addEventListener('timeupdate', () => { currentTimeSpan.textContent = formatTime(videoElement.currentTime); }); videoElement.addEventListener('durationchange', () => { durationSpan.textContent = formatTime(videoElement.duration); }); videoElement.addEventListener('loadedmetadata', () => { durationSpan.textContent = formatTime(videoElement.duration); }); } function formatTime(seconds) { const minutes = Math.floor(seconds / 60); const remainingSeconds = Math.floor(seconds % 60); return `${minutes}:${remainingSeconds < 10 ? '0' : ''}${remainingSeconds}`; } </script> </body> </html>
Debug
Known issues
gotchaThe primary way to use `cloudflare-video-element` is through a side-effect import (`import 'cloudflare-video-element';`) which registers the custom element. This means there is no named export for a `CloudflareVideoElement` class to import and instantiate directly in JavaScript. The element is intended for declarative use in HTML.
fix
Rely on the side-effect import to register the element globally, then use it as a standard HTML tag: `<cloudflare-video src="..."></cloudflare-video>`. For programmatic access, use `document.querySelector('cloudflare-video')`.
affects: >=1.0.0
gotchaLike all custom elements, `cloudflare-video-element` must be defined in the browser's `CustomElementRegistry` before any instances of the element are encountered in the DOM. If your script loads asynchronously or after your HTML renders, the element may not display correctly or will appear as an unknown tag.
fix
Ensure the import script is loaded and executed early in your application, ideally in the `<head>` with `type="module"`, or before the custom element appears in the `<body>`. If using a bundler, ensure the import statement is at the root of your application's entry point.
affects: >=1.0.0
gotchaAs a browser-specific custom element relying on DOM APIs, `cloudflare-video-element` is not directly compatible with server-side rendering (SSR) environments. Attempting to render this element on the server will result in errors related to missing DOM APIs.
fix
Implement client-only rendering for the custom element or use hydration techniques if you are in an SSR framework. For example, in React, you might use `useEffect` to mount the element on the client, or conditionally render it based on `typeof window !== 'undefined'`.
affects: >=1.0.0
Errors
Common errors & fixes
Uncaught DOMException: Failed to execute 'define' on 'CustomElementRegistry': the name "cloudflare-video" has already been used with this Registry.
The `cloudflare-video-element` script, which registers the custom element, has been loaded or imported multiple times.
fix
Ensure the `import 'cloudflare-video-element';` statement or the CDN script tag is present only once in your application's lifecycle, typically at your main entry point or in the HTML head.
The custom element <cloudflare-video> has not been defined.
You are attempting to use the `<cloudflare-video>` tag in your HTML before the JavaScript responsible for registering this custom element has executed.
fix
Verify that your `import 'cloudflare-video-element';` statement or `<script type="module" src="..."></script>` tag is loaded and executed *before* the `<cloudflare-video>` element appears in the document. Place script tags in the `<head>` or use deferred/async loading strategies carefully.
Upgrade
Version history
1.3.5latest on npm
Audit
Dependencies
custom-media-elementrequiredProvides a base class for custom media elements, abstracting common `HTMLMediaElement` behaviors and ensuring API compatibility. This package likely extends or utilizes it internally.
Agent activity
7 hits · last 30 days
node
4
OpenAI (training)
1
Resources
cloudflare-video-element — npm install cloudflare-video-element · libregistry