File tree 1 file changed +24
-1
lines changed
1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ The feature is available in Chromium-based browsers in M132 or later behind the
10
10
11
11
Here is an example of writing a ClipboardItem where text data is passed directly as string.
12
12
13
- ## Example
13
+ ## Example 1
14
14
15
15
``` javascript
16
16
async function writeToClipboard () {
@@ -31,4 +31,27 @@ async function writeToClipboard() {
31
31
console .error (e .message );
32
32
}
33
33
}
34
+ ```
35
+
36
+ Similarly, ClipboardItem data supports promise that resolves to string
37
+
38
+ ## Example 2
39
+
40
+ ``` javascript
41
+ async function writePromiseToClipboard () {
42
+ try {
43
+ const promise_text_string = Promise .resolve (" Hello World" );
44
+ const promise_html_string = Promise .resolve (" <h1>Hello World</h1>" );
45
+
46
+ const item = new ClipboardItem ({
47
+ " text/plain" : promise_text_string,
48
+ " text/html" : promise_html_string
49
+ });
50
+
51
+ await navigator .clipboard .write ([data]);
52
+ console .log (' Data copied to clipboard' );
53
+ } catch (e) {
54
+ console .error (e .message );
55
+ }
56
+ }
34
57
```
You can’t perform that action at this time.
0 commit comments