From ee39380edde1e6e28b933b77cbf9394e38c2e431 Mon Sep 17 00:00:00 2001 From: dm-xai Date: Mon, 27 Jan 2025 11:58:02 -0800 Subject: [PATCH] Handle missing "navigator.clipboard" In some cases navigator.clipboard can be undefined. For example on HTTP site (happens in DMZ environments). In such cases copy will fail. However, it can always be remediated on user side by using good old execCommand. This commit modifies code to avoid exception on copy. --- src/ButtonPanels.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ButtonPanels.tsx b/src/ButtonPanels.tsx index 93667871..3b6ecb57 100644 --- a/src/ButtonPanels.tsx +++ b/src/ButtonPanels.tsx @@ -79,10 +79,10 @@ export const EditButtons: React.FC = ({ value = data stringValue = type ? JSON.stringify(data, null, 2) : String(value) } - void navigator.clipboard.writeText(stringValue) - } - if (typeof enableClipboard === 'function') { - enableClipboard({ value, stringValue, path, key, type: copyType }) + void navigator.clipboard?.writeText(stringValue) + if (typeof enableClipboard === 'function') { + enableClipboard({ value, stringValue, path, key, type: copyType }) + } } }