diff --git a/packages/app-frontend/src/features/components/SelectedComponentPane.vue b/packages/app-frontend/src/features/components/SelectedComponentPane.vue index d55ddb054..d11d93053 100644 --- a/packages/app-frontend/src/features/components/SelectedComponentPane.vue +++ b/packages/app-frontend/src/features/components/SelectedComponentPane.vue @@ -4,7 +4,7 @@ import EmptyPane from '@front/features/layout/EmptyPane.vue' import RenderCode from './RenderCode.vue' import { defineComponent, ref, watch, computed } from 'vue' -import { getComponentDisplayName, SharedData } from '@vue-devtools/shared-utils' +import { copyToClipboard, getComponentDisplayName, SharedData } from '@vue-devtools/shared-utils' import { onKeyDown } from '@front/util/keyboard' import { useSelectedComponent } from './composable' @@ -45,7 +45,7 @@ export default defineComponent({ const showCopiedName = ref(false) let copiedNameTimeout function copyName () { - navigator.clipboard.writeText(displayName.value) + copyToClipboard(displayName.value) showCopiedName.value = true clearTimeout(copiedNameTimeout) copiedNameTimeout = setTimeout(() => { diff --git a/packages/shared-utils/src/util.ts b/packages/shared-utils/src/util.ts index 5776b52b2..040acddc6 100644 --- a/packages/shared-utils/src/util.ts +++ b/packages/shared-utils/src/util.ts @@ -741,7 +741,14 @@ export function copyToClipboard (state) { text = stringify(state, 'user') } - navigator.clipboard.writeText(text) + // @TODO navigator.clipboard is buggy in extensions + if (typeof document === 'undefined') return + const dummyTextArea = document.createElement('textarea') + dummyTextArea.textContent = text + document.body.appendChild(dummyTextArea) + dummyTextArea.select() + document.execCommand('copy') + document.body.removeChild(dummyTextArea) } export function isEmptyObject (obj) {