目录

Clipboard

The system clipboard manager.

import { clipboard } from '@mobrowser/api';

Example 

import { clipboard } from '@mobrowser/api';

clipboard.write('text/plain', 'Hello world')
const text = clipboard.read('text/plain')

Properties 

changeCount 

readonly changeCount: number;

The number of times the clipboard has been changed (macOS only).

Methods 

getTypes() 

getTypes(): ClipboardType[];

Returns the types available in the clipboard.

has() 

has(type: ClipboardType): boolean;

Checks if the clipboard has the given type.

ParameterTypeDescription
typeClipboardTypeThe type to check if the clipboard has.

read() 

read(type: ClipboardType): string;

Reads the data from the clipboard.

ParameterTypeDescription
typeClipboardTypeThe type of the data to read.

Return value 

The data from the clipboard.

readBytes() 

readBytes(type: ClipboardType): Uint8Array;

Reads the raw bytes stored under the given type from the clipboard.

Use this for binary data, such as a PDF, that read() would mangle when decoding it as text.

ParameterTypeDescription
typeClipboardTypeThe type of the data to read. Must contain only ASCII characters. On Apple platforms this is a Uniform Type Identifier, such as com.adobe.pdf; elsewhere it is a MIME type.

Return value 

The bytes from the clipboard, empty if the type is not present. @throws TypeError if type contains non-ASCII characters.

Example 

import { clipboard } from '@mobrowser/api';

const pdf = clipboard.readBytes(process.platform === 'darwin' ? 'com.adobe.pdf' : 'application/pdf')

write() 

write(type: ClipboardType, data: string): void;

Writes the data to the clipboard.

@throws TypeError if type contains non-ASCII characters.

ParameterTypeDescription
typeClipboardTypeThe type of the data to write. Must contain only ASCII characters.
datastringThe data to write to the clipboard.

writeBytes() 

writeBytes(type: ClipboardType, data: Uint8Array): void;

Writes the raw bytes to the clipboard under the given type.

Use this for binary data, such as a PDF, that write() would mangle when encoding it as text. The bytes are written verbatim, and can be read back with readBytes().

Like write(), this replaces the entire contents of the clipboard, so a binary payload cannot be combined with a plain-text fallback.

For other applications to recognize the data, type must be the identifier they expect. On Apple platforms that is a Uniform Type Identifier, such as com.adobe.pdf; elsewhere it is a MIME type, such as application/pdf. An identifier no other application knows, or a MIME type on Apple platforms, is still readable by readBytes() but is opaque to the rest of the system.

@throws TypeError if type contains non-ASCII characters, or if data is not a Uint8Array.

ParameterTypeDescription
typeClipboardTypeThe type of the data to write. Must contain only ASCII characters.
dataUint8ArrayThe bytes to write to the clipboard.

Example 

import { clipboard } from '@mobrowser/api';

const pdfType = process.platform === 'darwin' ? 'com.adobe.pdf' : 'application/pdf'
clipboard.writeBytes(pdfType, new Uint8Array(pdfBytes))

clear() 

clear(): void;

Clears the clipboard.