Skip to main content
The Bunny Player is an iframe, and player.js gives you a Player object for talking to it over postMessage. This guide builds a BunnyPlayer component that renders the iframe, emits its events, and exposes that object. The component also works under Nuxt server rendering. player.js is imported in onMounted, because it reads window when imported, and the iframe renders only after the library is available, because a Player has to exist before its iframe finishes loading.

Quickstart

1

Install player.js

player.js ships without types. Add a declaration file anywhere your tsconfig.json includes, for example player.js.d.ts. It covers the methods and events the Bunny Player supports:
player.js.d.ts
2

Create the component

components/BunnyPlayer.vue
In Nuxt, save it under components/ and it’s auto-imported. No <ClientOnly> wrapper is needed: the server renders the placeholder and the browser swaps in the iframe.
3

Render a video

Pass the library ID and video GUID from the video’s page in the dashboard:
params accepts any player parameter, such as captions, t, or muted.

Control playback

The ready event carries the Player. Keep it in a shallowRef, so Vue doesn’t wrap the instance in a deep reactive proxy, and call its methods from your own controls:
Getters take a callback, because the answer comes back from the iframe:
The player.js package on npm has no playback speed method, so send the command directly. The build bunny.net hosts adds setPlaybackRate() and getPlaybackRate(); see Methods.
Browsers block unmuted play() until the viewer has interacted with the page, so call mute() first if playback has to start without a click. Playback control API lists every method and event.

Track progress

timeupdate fires several times a second with { seconds, duration }. Throttle it before writing to your backend:
Pass the saved position back as the t parameter to resume from there.

Multiple players on one page

player.js matches the ready message to an iframe by its src, so two iframes with identical URLs confuse it. Give each one a parameter the player ignores, such as :params="{ instance: useId() }".

Load player.js from the CDN instead

To skip the npm dependency, load the hosted build and read window.playerjs. In Nuxt, add it to nuxt.config.ts:
nuxt.config.ts
In a plain Vue app, add the <script> tag to index.html. Replace the dynamic import in onMounted with playerjs.value = window.playerjs and declare the global:

Troubleshooting

player.js is being imported during server rendering. Keep import("player.js") inside onMounted. A static import playerjs from "player.js" at the top of <script setup> runs on the server in Nuxt.
The iframe finished loading before the Player existed. Render the iframe only after player.js has loaded, as the component above does, so both happen in the same update.
Every Player adds a message listener to window that is never removed. The active flag in the watcher cleanup keeps stale instances quiet, so check that yours flips it.
The library’s allowed domains, direct access block, or token authentication is rejecting the embed. See Embedding restrictions.
Last modified on September 21, 2026