Clipboard
The clipboard actions let your web app read from and write to the host system clipboard through the IDE. This is a text-only API with an extensible shape designed to support additional formats in the future.
import { getClipboard, setClipboard } from '@unextension/bridge'getClipboard()
Section titled “getClipboard()”Reads the current text content from the system clipboard.
const result = await getClipboard()console.log(result.text) // 'Hello from clipboard'Parameters
Section titled “Parameters”None.
Return value
Section titled “Return value”Promise<GetClipboardResult>
| Field | Type | Description |
|---|---|---|
text | string | The clipboard text content, or "" if empty/non-text |
setClipboard(text)
Section titled “setClipboard(text)”Writes text to the system clipboard.
const result = await setClipboard('Copied by my extension!')console.log(result.success) // trueParameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
text | string | The text to write to clipboard |
Return value
Section titled “Return value”Promise<SetClipboardResult>
| Field | Type | Description |
|---|---|---|
success | boolean | Whether the write succeeded |
Error handling
Section titled “Error handling”The two actions handle errors differently by design:
| Scenario | getClipboard | setClipboard |
|---|---|---|
| Clipboard access denied | Promise rejects | Resolves with { success: false } |
| Empty clipboard | Resolves with { text: "" } | — |
| Non-text content on clipboard | Resolves with { text: "" } | — |
getClipboard rejects on access failure because there is no meaningful fallback value. setClipboard resolves with { success: false } so callers can check the boolean without try/catch.
// Reading — use try/catch for access errorstry { const { text } = await getClipboard() console.log('Clipboard:', text)} catch (e) { console.error('Cannot access clipboard:', e)}
// Writing — check the success fieldconst { success } = await setClipboard('Hello')if (!success) { console.warn('Failed to write to clipboard')}Both result types are exported from @unextension/bridge:
import type { GetClipboardResult, SetClipboardResult } from '@unextension/bridge'GetClipboardResult
Section titled “GetClipboardResult”interface GetClipboardResult { text: string}SetClipboardResult
Section titled “SetClipboardResult”interface SetClipboardResult { success: boolean}