@tauri-apps/plugin-clipboard-manager
Read and write to the system clipboard.
Functions
clear()
function clear(): Promise<void>
Clears the clipboard.
Platform-specific
- Android: Only supported on SDK 28+. For older releases we write an empty string to the clipboard instead.
Returns
Promise
<void
>
Example
import { clear } from '@tauri-apps/plugin-clipboard-manager';await clear();
Since
2.0.0
readImage()
function readImage(): Promise<Image>
Gets the clipboard content as Uint8Array image.
Platform-specific
- Android / iOS: Not supported.
Returns
Promise
<Image
>
Example
import { readImage } from '@tauri-apps/plugin-clipboard-manager';
const clipboardImage = await readImage();const blob = new Blob([await clipboardImage.rbga()], { type: 'image' })const url = URL.createObjectURL(blob)
Since
2.0.0
readText()
function readText(): Promise<string>
Gets the clipboard content as plain text.
Returns
Promise
<string
>
Example
import { readText } from '@tauri-apps/plugin-clipboard-manager';const clipboardText = await readText();
Since
2.0.0
writeHtml()
function writeHtml(html, altText?): Promise<void>
- Writes HTML or fallbacks to write provided plain text to the clipboard.
Platform-specific
- Android / iOS: Not supported.
Parameters
Parameter | Type |
---|---|
html | string |
altText ? | string |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
import { writeHtml, readHtml } from '@tauri-apps/plugin-clipboard-manager';await writeHtml('<h1>Tauri is awesome!</h1>', 'plaintext');await writeHtml('<h1>Tauri is awesome!</h1>', '<h1>Tauri is awesome</h1>'); // Will write "<h1>Tauri is awesome</h1>" as plain textassert(await readText(), '<h1>Tauri is awesome!</h1>');
Since
2.0.0
writeImage()
function writeImage(image): Promise<void>
Writes image buffer to the clipboard.
Platform-specific
- Android / iOS: Not supported.
Parameters
Parameter | Type |
---|---|
image | | string | number [] | ArrayBuffer | Uint8Array <ArrayBufferLike > | Image |
Returns
Promise
<void
>
Example
import { writeImage } from '@tauri-apps/plugin-clipboard-manager';const buffer = [ // A red pixel 255, 0, 0, 255,
// A green pixel 0, 255, 0, 255,];await writeImage(buffer);
@returns A promise indicating the success or failure of the operation.
@since 2.0.0
**Source**: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/clipboard-manager/guest-js/index.ts#L73
***
<a id="writetext" name="writetext"></a>
### writeText()
```tsfunction writeText(text, opts?): Promise<void>
Writes plain text to the clipboard.
Parameters
Parameter | Type |
---|---|
text | string |
opts ? | object |
opts.label ? | string |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
import { writeText, readText } from '@tauri-apps/plugin-clipboard-manager';await writeText('Tauri is awesome!');assert(await readText(), 'Tauri is awesome!');
Since
2.0.0
© 2024 Tauri Contributors. CC-BY / MIT