clipboard module

Note

This namespace is in Beta and provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Interact with the system clipboard.

Functions

hasPermission()

Checks whether the app has permission to read from the system clipboard.

isSupported()

Checks if clipboard capability is supported by the host

read()

Function to read data from clipboard.

requestPermission()

Requests permission to read from the system clipboard.

write(Blob)

Function to copy data to clipboard.

Function Details

hasPermission()

Note

This API is in Beta and provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Checks whether the app has permission to read from the system clipboard.

function hasPermission(): Promise<boolean>

Returns

Promise<boolean>

A promise that resolves to true if clipboard-read permission has been granted, or false if permission has not been granted.

isSupported()

Warning

This API is now deprecated.

As of TeamsJS v2.54.0, the clipboard capability is deprecated. These APIs may stop working at any time without notice: support for this capability in Teams and other host apps may be removed entirely and independently of a TeamsJS major release, so continued functionality is not guaranteed. The intended long-term replacement is the standardized Clipboard API provided by the browser (Clipboard API, navigator.clipboard). For browser-native reads, use hasPermission and requestPermission before calling navigator.clipboard.read() from a user gesture.

Note

This API is in Beta and provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Checks if clipboard capability is supported by the host

function isSupported(): boolean

Returns

boolean

boolean to represent whether the clipboard capability is supported

read()

Warning

This API is now deprecated.

As of TeamsJS v2.54.0, the clipboard capability is deprecated. These APIs may stop working at any time without notice: support for this capability in Teams and other host apps may be removed entirely and independently of a TeamsJS major release, so continued functionality is not guaranteed. The intended long-term replacement is the standardized Clipboard API provided by the browser (Clipboard API, navigator.clipboard). For browser-native reads, use hasPermission and requestPermission before calling navigator.clipboard.read() from a user gesture.

Function to read data from clipboard.

function read(): Promise<Blob>

Returns

Promise<Blob>

A promise blob which resolves to the data read from the clipboard or rejects stating the reason for failure. Note: Returned blob type will contain one of the MIME type image/png, text/plain or text/html.

requestPermission()

Note

This API is in Beta and provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Requests permission to read from the system clipboard.

function requestPermission(): Promise<boolean>

Returns

Promise<boolean>

A promise that resolves to true if clipboard-read permission was granted, or false if permission was not granted.

Remarks

The host may need to reload the app frame after the permission is first granted before navigator.clipboard.read() is available to the existing frame.

write(Blob)

Warning

This API is now deprecated.

As of TeamsJS v2.54.0, the clipboard capability is deprecated. These APIs may stop working at any time without notice: support for this capability in Teams and other host apps may be removed entirely and independently of a TeamsJS major release, so continued functionality is not guaranteed. The intended long-term replacement is the standardized Clipboard API provided by the browser (Clipboard API, navigator.clipboard). For browser-native reads, use hasPermission and requestPermission before calling navigator.clipboard.read() from a user gesture.

Function to copy data to clipboard.

function write(blob: Blob): Promise<void>

Parameters

blob

Blob

A Blob object representing the data to be copied to clipboard.

Returns

Promise<void>

A string promise which resolves to success message from the clipboard or rejects with error stating the reason for failure.

Remarks

Note: clipboard.write only supports Text, HTML, PNG, and JPEG data format. MIME type for Text -> text/plain, HTML -> text/html, PNG/JPEG -> image/(png | jpeg) Also, JPEG will be converted to PNG image when copying to clipboard.