File tree Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Expand file tree Collapse file tree 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
1010
1111Here is an example of writing a ClipboardItem where text data is passed directly as string.
1212
13- ## Example
13+ ## Example 1
1414
1515``` javascript
1616async function writeToClipboard () {
@@ -31,4 +31,27 @@ async function writeToClipboard() {
3131 console .error (e .message );
3232 }
3333}
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+ }
3457```
You can’t perform that action at this time.
0 commit comments