Skip to content

Commit 7a3e42f

Browse files
committed
feat: copy to clipboard: don't stringify primitive values, fix #1002
1 parent 5d84a8b commit 7a3e42f

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

packages/shared-utils/src/util.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -701,13 +701,15 @@ function escapeChar (a) {
701701
}
702702

703703
export function copyToClipboard (state) {
704-
if (typeof document === 'undefined') return
705-
const dummyTextArea = document.createElement('textarea')
706-
dummyTextArea.textContent = stringify(state)
707-
document.body.appendChild(dummyTextArea)
708-
dummyTextArea.select()
709-
document.execCommand('copy')
710-
document.body.removeChild(dummyTextArea)
704+
let text: string
705+
706+
if (typeof state !== 'object') {
707+
text = String(state)
708+
} else {
709+
text = stringify(state)
710+
}
711+
712+
navigator.clipboard.writeText(text)
711713
}
712714

713715
export function isEmptyObject (obj) {

0 commit comments

Comments
 (0)