Skip to content

orbit-clipboard ​

@c9up/orbit-clipboard: the system clipboard, with the same two calls in the browser and on a phone. Guide: Device APIs.

Installation ​

bash
pnpm add @c9up/orbit-clipboard

On a phone, React Native's autolinking adds the native module to an app built by ream android:*; there is nothing to wire.

Entry points ​

ImportContents
@c9up/orbit-clipboardwriteText, readText and the error class. The import resolves per platform: the default build in the browser and on the server, the react-native build (the condition and the react-native field) on a phone. Both builds export the same names.
PlatformWhat the calls reach
Browsernavigator.clipboard, on a secure page (https, localhost). Reading asks the user.
Phone (Android)The app's OrbitClipboard TurboModule over ClipboardManager. Android lets an app read the clipboard only while it has focus (10+) and tells the user when it does (13+).
ServerNo clipboard: both calls reject with E_ORBIT_CLIPBOARD_UNAVAILABLE.

Plain text only.

Exports ​

ExportKindDescription
writeTextfunctionPuts text on the system clipboard.
readTextfunctionReads the text on the system clipboard.
errorsnamespaceThe package's errors, one class per code, see Errors

Functions ​

FunctionSignatureDescription
writeTextwriteText(text: string): Promise<void>Puts text on the system clipboard.
readTextreadText(): Promise<string>The text on the system clipboard; "" when it holds none.

Errors ​

Each code is a class of the errors export, the same in the browser and on a phone; a platform failure is kept as cause.

CodeRaised when
E_ORBIT_CLIPBOARD_UNAVAILABLEThere is no clipboard to reach: the server, a page that is not a secure context, or an app built without the native module.
E_ORBIT_CLIPBOARD_DENIEDThe platform refused: no permission, or the page or app was not in focus.

See also ​