Skip to content

Commit 7899b73

Browse files
committed
fix: copy no longer working
1 parent ec834d0 commit 7899b73

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

packages/app-frontend/src/features/components/SelectedComponentPane.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import EmptyPane from '@front/features/layout/EmptyPane.vue'
44
import RenderCode from './RenderCode.vue'
55
66
import { defineComponent, ref, watch, computed } from 'vue'
7-
import { getComponentDisplayName, SharedData } from '@vue-devtools/shared-utils'
7+
import { copyToClipboard, getComponentDisplayName, SharedData } from '@vue-devtools/shared-utils'
88
import { onKeyDown } from '@front/util/keyboard'
99
import { useSelectedComponent } from './composable'
1010
@@ -45,7 +45,7 @@ export default defineComponent({
4545
const showCopiedName = ref(false)
4646
let copiedNameTimeout
4747
function copyName () {
48-
navigator.clipboard.writeText(displayName.value)
48+
copyToClipboard(displayName.value)
4949
showCopiedName.value = true
5050
clearTimeout(copiedNameTimeout)
5151
copiedNameTimeout = setTimeout(() => {

packages/shared-utils/src/util.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,14 @@ export function copyToClipboard (state) {
741741
text = stringify(state, 'user')
742742
}
743743

744-
navigator.clipboard.writeText(text)
744+
// @TODO navigator.clipboard is buggy in extensions
745+
if (typeof document === 'undefined') return
746+
const dummyTextArea = document.createElement('textarea')
747+
dummyTextArea.textContent = text
748+
document.body.appendChild(dummyTextArea)
749+
dummyTextArea.select()
750+
document.execCommand('copy')
751+
document.body.removeChild(dummyTextArea)
745752
}
746753

747754
export function isEmptyObject (obj) {

0 commit comments

Comments
 (0)