Skip to content

Commit eeef7ba

Browse files
Merge pull request #514 from Luisgustavom1/fix/copy-paste-on-chrome-134
use navigator clipboard if has support #510
2 parents 7a40e1b + f4c7854 commit eeef7ba

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/lib/Functions/handleCopy.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@ export function handleCopy(event: ClipboardEvent, state: State, removeValues = f
1515
}
1616

1717
export function copyDataCommands(event: ClipboardEvent, state: State, div: HTMLDivElement): void {
18+
// how document.execCommand is deprecated, we need try use Clipboard API if is available
19+
// https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API
1820
const supportNavigatorClipboard = !!navigator?.clipboard?.write;
1921

2022
if (isBrowserSafari()) {
2123
event.clipboardData.setData('text/html', div.innerHTML);
2224
} else if (supportNavigatorClipboard) {
2325
const clipboardItemData = {
24-
"text/html": div.innerHtml,
25-
};
26+
'text/html': div.innerHTML,
27+
};
2628
const clipboardItem = new ClipboardItem(clipboardItemData);
27-
await navigator.clipboard.write([clipboardItem]);
29+
navigator.clipboard.write([clipboardItem]).then(() => ({}));
2830
} else {
2931
document.body.appendChild(div);
3032
div.focus();

0 commit comments

Comments
 (0)