From 64ab79fc6b42fbd53a39d7bc861b530c4db2d0cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?nicole=20miko=C5=82ajczyk?= Date: Tue, 17 Mar 2026 18:01:23 +0100 Subject: [PATCH] nicolium: do not default to document.execCommand for copy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: nicole mikołajczyk --- .../src/components/copyable-input.tsx | 11 ++------ .../nicolium/src/components/site-error.tsx | 20 +++---------- packages/nicolium/src/utils/copy.ts | 28 +++++++++++-------- 3 files changed, 22 insertions(+), 37 deletions(-) diff --git a/packages/nicolium/src/components/copyable-input.tsx b/packages/nicolium/src/components/copyable-input.tsx index 16e261ea6..587194de8 100644 --- a/packages/nicolium/src/components/copyable-input.tsx +++ b/packages/nicolium/src/components/copyable-input.tsx @@ -3,6 +3,7 @@ import { FormattedMessage } from 'react-intl'; import Button from '@/components/ui/button'; import Input from '@/components/ui/input'; +import copy from '@/utils/copy'; interface ICopyableInput { /** Text to be copied. */ @@ -18,15 +19,7 @@ const CopyableInput: React.FC = ({ value, type = 'text', onCopy const input = useRef(null); const selectInput = () => { - input.current?.select(); - - if (navigator.clipboard) { - navigator.clipboard.writeText(value); - } else { - document.execCommand('copy'); - } - - onCopy?.(); + copy(value, onCopy, input.current); }; return ( diff --git a/packages/nicolium/src/components/site-error.tsx b/packages/nicolium/src/components/site-error.tsx index ab3766edf..ddba1126f 100644 --- a/packages/nicolium/src/components/site-error.tsx +++ b/packages/nicolium/src/components/site-error.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useRef, useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { defineMessages, FormattedMessage, useIntl } from 'react-intl'; import { NODE_ENV } from '@/build-config'; @@ -8,6 +8,7 @@ import { useLogo } from '@/hooks/use-logo'; import { captureSentryException } from '@/sentry'; import KVStore from '@/storage/kv-store'; import sourceCode from '@/utils/code'; +import copy from '@/utils/copy'; import { isNetworkError } from '@/utils/errors'; import { unregisterSW } from '@/utils/sw'; @@ -27,7 +28,6 @@ const SiteError: ErrorRouteComponent = ({ error, info }) => { const intl = useIntl(); const { links, sentryDsn } = useFrontendConfig(); const { src: logoSrc } = useLogo(); - const textarea = useRef(null); const [browser, setBrowser] = useState(); const [sentryEventId, setSentryEventId] = useState(); @@ -48,12 +48,7 @@ const SiteError: ErrorRouteComponent = ({ error, info }) => { }; const handleCopy: React.MouseEventHandler = () => { - if (!textarea.current) return; - - textarea.current.select(); - textarea.current.setSelectionRange(0, 99999); - - document.execCommand('copy'); + copy(errorText); }; useEffect(() => { @@ -146,14 +141,7 @@ const SiteError: ErrorRouteComponent = ({ error, info }) => { )} {errorText && ( -