Skip to content
Tauri

@tauri-apps/plugin-clipboard-manager

Read and write to the system clipboard.

Functions

clear()

function clear(): Promise<void>

Clears the clipboard.

Returns

Promise<void>

Example

import { clear } from '@tauri-apps/plugin-clipboard-manager';
await clear();

Since

2.0.0

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/clipboard-manager/guest-js/index.ts#L124


readImage()

function readImage(): Promise<Image>

Gets the clipboard content as Uint8Array image.

Returns

Promise<Image>

Example

import { readImage } from '@tauri-apps/plugin-clipboard-manager';
const clipboardImage = await readImage();
const blob = new Blob([clipboardImage.bytes], { type: 'image' })
const url = URL.createObjectURL(blob)

Since

2.0.0

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/clipboard-manager/guest-js/index.ts#L88


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

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/clipboard-manager/guest-js/index.ts#L46


writeHtml()

function writeHtml(html, altHtml?): Promise<void>
  • Writes HTML or fallbacks to write provided plain text to the clipboard.

Parameters

ParameterType
htmlstring
altHtml?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 text
assert(await readText(), '<h1>Tauri is awesome!</h1>');

Since

2.0.0

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/clipboard-manager/guest-js/index.ts#L108


writeImage()

function writeImage(image): Promise<void>

Writes image buffer to the clipboard.

Parameters

ParameterType
image| string | number[] | ArrayBuffer | Uint8Array | 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#L68
***
<a id="writetext" name="writetext"></a>
### writeText()
```ts
function writeText(text, opts?): Promise<void>

Writes plain text to the clipboard.

Parameters

ParameterType
textstring
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

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/clipboard-manager/guest-js/index.ts#L27


© 2024 Tauri Contributors. CC-BY / MIT