WebExeBuilder Documentation

readText

Category: Clipboard Operations

Namespace: web.clipboard.readText

Description

Reads the current text content of the Windows clipboard and returns it as a string. If the clipboard is empty or contains non-text content (e.g. an image), an empty string is returned.

Syntax

const text = await web.clipboard.readText();

Parameters

None.

Returns

Promise<string> - The current clipboard text, or an empty string if the clipboard is empty or contains no text. Throws on error.

Examples

Paste clipboard content into an editor

document.getElementById('btn-paste').addEventListener('click', async function() {
    const text = await web.clipboard.readText();
    if (text) {
        document.getElementById('editor').value += text;
    } else {
        showStatus('Clipboard is empty');
    }
});

Check clipboard before pasting

async function pasteFromClipboard() {
    const text = await web.clipboard.readText();
    if (!text) {
        alert('Nothing to paste — clipboard is empty.');
        return;
    }
    insertTextAtCursor(text);
}

Round-trip: copy then read back to verify

const original = 'Hello, World!';
await web.clipboard.writeText({ text: original });

const pasted = await web.clipboard.readText();
if (pasted === original) {
    console.log('Clipboard round-trip verified ✓');
}

Use Cases

  • Paste buttons in text editors and note-taking apps
  • Importing data copied from another application (spreadsheet rows, file paths, URLs)
  • Verifying clipboard content before a paste operation
  • Building clipboard history or monitoring tools

Notes

  • Returns an empty string (not null) when the clipboard contains no text
  • If the clipboard holds non-text content (e.g. a copied image or file), returns an empty string
  • Newlines in the clipboard text are preserved as \n in the returned string
  • For writing to the clipboard, use web.clipboard.writeText()