Table of Contents

Class Clipboard

Namespace
CSharpToJavaScript.APIs.JS
Assembly
CSharpToJavaScript.dll

The Clipboard interface of the Clipboard API provides read and write access to the contents of the system clipboard.
This allows a web application to implement cut, copy, and paste features.

[Value("Clipboard")]
public class Clipboard : EventTarget
Inheritance
Clipboard
Inherited Members

Remarks

The system clipboard is exposed through the global Clipboard property.

All of the Clipboard API methods operate asynchronously; they return a Promise which is resolved once the clipboard access has been completed.
The promise is rejected if clipboard access is denied.

All the methods require a secure context.
Additional requirements for using the API are discussed in the Security consideration section of the API overview topic.

-ExecCommand(string, bool, string)

See also on MDN

Constructors

Clipboard()

public Clipboard()

Methods

Read(ClipboardUnsanitizedFormats)

The read() method of the Clipboard interface requests a copy of the clipboard's contents, fulfilling the returned {{jsxref("Promise")}} with the data.

[Value("read")]
public Task<List<ClipboardItem>> Read(ClipboardUnsanitizedFormats formats = null)

Parameters

formats ClipboardUnsanitizedFormats

Returns

Task<List<ClipboardItem>>

A {{jsxref("Promise")}} that resolves with an array of ClipboardItem objects containing the clipboard's contents.

Remarks

The method can in theory return arbitrary data (unlike ReadText(), which can only return text).
Browsers commonly support reading text, HTML, and PNG image data.

-Clipboard API
-Unblocking clipboard access on web.dev
-Unsanitized HTML in the Async Clipboard API on developer.chrome.com
-ReadText()
-WriteText(string)
-Write(List<ClipboardItem>)

See also on MDN

ReadText()

The readText() method of the Clipboard interface returns a {{jsxref("Promise")}} which fulfills with a copy of the textual contents of the system clipboard.

[Value("readText")]
public Task<string> ReadText()

Returns

Task<string>

A Promise that resolves with a string containing the textual contents of the clipboard.Returns an empty string if the clipboard is empty, does not contain text, or does not include a textual representation among the objects representing the clipboard&apos;s contents.

Remarks

Write(List<ClipboardItem>)

The write() method of the Clipboard interface writes arbitrary ClipboardItem data such as images and text to the clipboard, fulfilling the returned {{jsxref("Promise")}} on completion.
This can be used to implement cut and copy functionality.

[Value("write")]
public Task<GlobalObject.Undefined> Write(List<ClipboardItem> data)

Parameters

data List<ClipboardItem>

Returns

Task<GlobalObject.Undefined>

A Promise which is resolved when the data has been written to the clipboard.
Note that if the underlying OS does not support multiple native clipboard items on the system clipboard, then only the first ClipboardItem in the array is written.The promise is rejected if the clipboard is unable to write to the clipboard.

Remarks

The method can in theory write arbitrary data (unlike WriteText(string), which can only write text).
Browsers commonly support writing text, HTML, and PNG image data.

-Clipboard API
-Image support for Async Clipboard article
-WriteText(string)
-Read(ClipboardUnsanitizedFormats)
-ReadText()

See also on MDN

WriteText(string)

The writeText() method of the Clipboard interface writes the specified text to the system clipboard, returning a {{jsxref("Promise")}} that is resolved once the system clipboard has been updated.

[Value("writeText")]
public Task<GlobalObject.Undefined> WriteText(string data)

Parameters

data string

Returns

Task<GlobalObject.Undefined>

A Promise that is resolved once the clipboard's contents have been updated.

Remarks