Provides access to the Clipboard API for reading / writing text strings. This requires a secure context.

Note: writeText will attempt to use the older execCommand if available when navigator.clipboard is not available.

Constructors

Methods

Constructors

Methods

  • Uses navigator.clipboard if available to read text from the clipboard.

    Note: Always returns undefined when navigator.clipboard is not available or the clipboard contains the empty string.

    Parameters

    • OptionalactiveWindow: Window

      Optional active current window.

    Returns Promise<string>

    The current clipboard text or undefined.

  • Uses navigator.clipboard if available then falls back to document.execCommand('copy') if available to copy the given text to the clipboard.

    Parameters

    • text: string

      Text to copy to the browser clipboard.

    • OptionalactiveWindow: Window

      Optional active current window.

    Returns Promise<boolean>

    Copy successful.