@napacitor/clipboard
System clipboard plugin (corresponds to @capacitor/clipboard).
Installation
To use npm:
npm install @napacitor/clipboard
To use yarn:
yarn add @napacitor/clipboard
Sync native files:
npx nap sync
Usage
import { Clipboard } from '@napacitor/clipboard';
await Clipboard.write({ string: 'Content to copy' });
const result = await Clipboard.read();
console.log(result.value); // Clipboard text
How It Works
Wraps the APIs described in the .NET MAUI Clipboard documentation: Clipboard.Default.SetTextAsync / GetTextAsync. The MAUI Essentials clipboard only supports text, so writing images (the image parameter) throws NOT_IMPLEMENTED.
Permissions
Android
No additional configuration required.
iOS
No additional configuration required.
Windows
No additional configuration required.
API
write(options)
Writes to the clipboard. Throws INVALID_ARGUMENTS when neither string nor image is provided.
| Param | Type |
|---|---|
options | WriteOptions |
Returns: Promise<void>
read()
Reads the clipboard text (empty clipboard returns an empty string).
Returns: Promise<ReadResult>
Interfaces
WriteOptions
| Prop | Type | Description |
|---|---|---|
string | string | Text to copy. |
image | string | Image to copy (base64 data URI). The MAUI Essentials clipboard only supports text, so the native side throws NOT_IMPLEMENTED. |
ReadResult
| Prop | Type | Description |
|---|---|---|
value | string | Clipboard text (empty clipboard returns an empty string). |