Skip to content
Kunkun

Clipboard

Docs: https://docs.api.kunkun.sh/interfaces/ui.IClipboard

API and Permissions

  • readText: [ clipboard:read-text,clipboard:read-all ]
  • writeText: [ clipboard:write-text,clipboard:write-all ]
  • readImageBase64: [ clipboard:read-all,clipboard:read-image ]
  • readImageBinary: [ clipboard:read-all,clipboard:read-image ]
  • writeImageBase64: [ clipboard:write-all,clipboard:write-image ]
  • writeImageBinary: [ clipboard:write-all,clipboard:write-image ]
  • readFiles: [ clipboard:read-all,clipboard:read-files ]
  • writeFiles: [ clipboard:write-all,clipboard:write-files ]
  • readRtf: [ clipboard:read-all,clipboard:read-text ]
  • writeRtf: [ clipboard:write-all,clipboard:write-text ]
  • readHtml: [ clipboard:read-all,clipboard:read-text ]
  • writeHtml: [ clipboard:write-all,clipboard:write-text ]
  • writeHtmlAndText: [ clipboard:write-all,clipboard:write-text ]
  • hasText: [ ]
  • hasRTF: [ ]
  • hasHTML: [ ]
  • hasImage: [ ]
  • hasFiles: [ ]

Sample Usage

// Check if the clipboard has data
const hasFiles: boolean = await clipboard.hasFiles()
const hasHTML: boolean = await clipboard.hasHTML()
const hasImage: boolean = await clipboard.hasImage()
const hasRTF: boolean = await clipboard.hasRTF()
const hasText: boolean = await clipboard.hasText()
// Read data from the clipboard
const text: string = await clipboard.readText()
const imageBinary: Blob = await clipboard.readImageBinary('Blob') as Blob
const imageBase64: string = await clipboard.readImageBase64()
const html: string = await clipboard.readHtml()
const files: string[] = await clipboard.readFiles()
const rtf: string = await clipboard.readRtf()
// Write data to the clipboard
await clipboard.writeText('Hello, World!')
await clipboard.writeImageBinary(Array.from(new Uint8Array(await imageBinary.arrayBuffer())));
await clipboard.writeHtmlAndText('<h1>Hello, World!</h1>', 'Hello, World!')
await clipboard.writeFiles(['file1.txt', 'file2.txt'])
await clipboard.writeRtf(rtf)
await clipboard.writeImageBase64(imageBase64)