fn

useDocumentPiP

v0.0.14testeddemo

Reactive wrapper around the Document Picture-in-Picture API for rendering arbitrary DOM in an always-on-top window.

Examples

ts
const { isSupported, pipWindow, open } = useDocumentPiP();
async function popOut(content: HTMLElement) {
  const win = await open({ width: 320, height: 240 });
  win?.document.body.append(content);
}
ts
// Move a player into the PiP window and track open state
const { isOpen, pipWindow, open, close } = useDocumentPiP();
watchEffect(() => {
  if (pipWindow.value)
    pipWindow.value.document.body.append(playerEl);
});

Demo

Loading demo…

Signature

ts
export function useDocumentPiP(options: UseDocumentPiPOptions ={ ... }

Parameters

ParameterTypeDescription
options?UseDocumentPiPOptionsOptions

Returns

UseDocumentPiPReturnisSupported, pipWindow, isOpen, error, open(), and close()
PropertyTypeDescription
isSupportedComputedRef<boolean>Whether the Document Picture-in-Picture API is supported
pipWindowShallowRef<Window | null>The active Picture-in-Picture Window, or null when none is open
isOpenComputedRef<boolean>Whether a Picture-in-Picture window is currently open
errorShallowRef<unknown | null>The last error thrown by open(), or null
open(pipOptions?: DocumentPictureInPictureOptions) => Promise<Window | undefined>Open a Picture-in-Picture window. Must be called from a user gesture. Resolves with the new Window, or undefined when unsupported.
close() => voidClose the active Picture-in-Picture window, if any