Skip to content

Function: copyToClipboard() ​

copyToClipboard(str): Promise<0 | 1 | 2>

Defined in: packages/core/src/str/copyToClipboard.ts:22

Copies text to browser clipboard.

CAUTION: Based on browser security policy it may be required to invoke copyToClipboard from an user-generated event handler.

Invoking from non-browser environment will already resolve with 0.

This function first attempts to use the modern, asynchronous Clipboard API (navigator.clipboard.writeText). If that fails or is unavailable, it falls back to the legacy document.execCommand('copy') method.

Parameters ​

str ​

string

Returns ​

Promise<0 | 1 | 2>

number 0: copy failed (both methods attempted) 1: modern API success 2: fallback success