clipboard and clipboard-polyfill focus on browser integration, clipboardy provides a Node system-clipboard API with a distinct browser entry, and copy-paste integrates with operating-system clipboard tools. Choose the actual runtime and asynchronous contract first.
A browser page and a Node process do not reach the clipboard through the same interface. Browser event integration, a browser API-shaped module and operating-system command execution are separate routes. Choose one that matches where the code actually runs.
Clipboard.js connects trigger elements to copy/cut behavior and emits success/error events. Its element and selection model fits a browser page; event listeners and instances need appropriate cleanup when the interface is removed.
Clipboard Polyfill supplies Promise-based methods shaped like the browser clipboard API. Its normal module import differs from the explicit global-overwrite entry. Browser support, interaction requirements and available data formats still matter. Providing the API shape in a DOM test environment is not proof that a real operating-system clipboard is available there.
Clipboardy exposes system clipboard operations for Node and declares Node >=20 in the current package. The applicable platform and session still determine whether a desktop clipboard is available; a headless service environment should not be assumed to behave like a logged-in desktop.
Its browser entry uses browser clipboard facilities and supports asynchronous operations. Node-oriented synchronous methods are not implemented by that entry. A wrapper shared between browser and Node code should not call a sync method merely because it exists in a Node example.
Copy Paste delegates to operating-system clipboard utilities. Those tools and the process environment are part of deployment, particularly on Linux systems. Follow the selected operation's callback or synchronous contract rather than assuming all desktop clipboard functions have the same completion model.
Use element events for a browser trigger integration, asynchronous browser methods for an application-owned function, or a desktop integration for an actual Node desktop workflow. Check the needed operation—writing text, reading text or another format—rather than assuming a package that copies can read or that browser and server exports are identical.
Use its Node system clipboard read/write methods with the current Node >=20 requirement. Its browser entry only supplies the supported asynchronous browser behavior; synchronous methods are not available there.
Use browser element triggers, selection and success/error events. Manage the instance lifecycle; it is not a Node desktop clipboard API.
Use its asynchronous browser clipboard-shaped methods for a documented compatibility need. A non-browser API shape does not by itself provide access to the desktop clipboard.
Use its operating-system command integration when the target environment has the required clipboard utilities. Its callback or synchronous forms should be checked for the selected operation and runtime.
Access the system clipboard (copy/paste)
Cross-platform. Supports: macOS, Windows, Linux (including Wayland), OpenBSD, FreeBSD, Android with Termux, and modern browsers.
npm install clipboardy
import clipboard from 'clipboardy';
await clipboard.write('🦄');
await clipboard.read();
//=> '🦄'
// Or use the synchronous API
clipboard.writeSync('🦄');
clipboard.readSync();
//=> '🦄'
Browser usage: Requires a secure context (HTTPS). Synchronous methods are not available in browsers.
Write (copy) to the clipboard asynchronously.
Returns a Promise<void>.
Type: string
The text to write to the clipboard.
await clipboard.write('🦄');
Read (paste) from the clipboard asynchronously.
Returns a Promise<string>.
const content = await clipboard.read();
//=> '🦄'
Write (copy) to the clipboard synchronously.
Doesn't work in browsers.
Type: string
The text to write to the clipboard.
clipboard.writeSync('🦄');
Read (paste) from the clipboard synchronously.
Returns a string.
Doesn't work in browsers.
const content = clipboard.readSync();
//=> '🦄'
Write (copy) images to the clipboard asynchronously.
Returns a Promise<void>.
Only supported on macOS. On other platforms, this is a no-op.
Type: string[]
The file paths of the images to write to the clipboard. Supports any image type that macOS supports, including PNG, JPEG, HEIC, WebP, and GIF.
await clipboard.writeImages(['/path/to/image.png']);
Read images from the clipboard asynchronously.
Returns a Promise<string[]> with file paths to temporary PNG files. You are responsible for cleaning up the files.
Only supported on macOS. On other platforms, this returns an empty array.
const filePaths = await clipboard.readImages();
Check if the clipboard contains images.
Returns a Promise<boolean>.
Only supported on macOS. On other platforms, this returns false.
const hasImages = await clipboard.hasImages();
No. Clipboard operations on Linux require a display server (X11 or Wayland). Headless environments like CI servers or Raspberry Pi without a desktop environment do not have a system clipboard.
The Linux binary is just a bundled version of xsel. The source for the Windows binary can be found here.
On Windows, clipboardy first tries the native PowerShell cmdlets (Set-Clipboard/Get-Clipboard) and falls back to the bundled binary if PowerShell is unavailable or restricted.
Yes. On Linux, clipboardy automatically detects Wayland sessions and uses wl-clipboard when available. If not, it gracefully falls back to X11 tools. Also works with WSLg (Windows Subsystem for Linux GUI). Install wl-clipboard using your distribution's package manager.