Skip to content

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'

Reads the current text content from the system clipboard.

const result = await getClipboard()
console.log(result.text) // 'Hello from clipboard'

None.

Promise<GetClipboardResult>

FieldTypeDescription
textstringThe clipboard text content, or "" if empty/non-text

Writes text to the system clipboard.

const result = await setClipboard('Copied by my extension!')
console.log(result.success) // true
ParameterTypeDescription
textstringThe text to write to clipboard

Promise<SetClipboardResult>

FieldTypeDescription
successbooleanWhether the write succeeded

The two actions handle errors differently by design:

ScenariogetClipboardsetClipboard
Clipboard access deniedPromise rejectsResolves with { success: false }
Empty clipboardResolves with { text: "" }
Non-text content on clipboardResolves 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 errors
try {
const { text } = await getClipboard()
console.log('Clipboard:', text)
} catch (e) {
console.error('Cannot access clipboard:', e)
}
// Writing — check the success field
const { 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'
interface GetClipboardResult {
text: string
}
interface SetClipboardResult {
success: boolean
}