Fixed: Copy to clipboard in non-secure contexts

(cherry picked from commit 3828e475cc8860e74cdfd8a70b4f886de7f9c5c3)
pull/2252/head
Bogdan 3 months ago
parent 94cf07ddb4
commit 3f07c50cc5

@ -1,3 +1,4 @@
import copy from 'copy-to-clipboard';
import React, { useCallback, useEffect, useState } from 'react';
import FormInputButton from 'Components/Form/FormInputButton';
import Icon from 'Components/Icon';
@ -37,10 +38,16 @@ export default function ClipboardButton({
const handleClick = useCallback(async () => {
try {
await navigator.clipboard.writeText(value);
if ('clipboard' in navigator) {
await navigator.clipboard.writeText(value);
} else {
copy(value);
}
setState('success');
} catch (_) {
} catch (e) {
setState('error');
console.error(`Failed to copy to clipboard`, e);
}
}, [value]);

@ -38,6 +38,7 @@
"chart.js": "4.4.4",
"classnames": "2.5.1",
"connected-react-router": "6.9.3",
"copy-to-clipboard": "3.3.3",
"element-class": "0.2.2",
"filesize": "10.1.6",
"history": "4.10.1",

@ -2484,6 +2484,13 @@ copy-anything@^2.0.1:
dependencies:
is-what "^3.14.1"
copy-to-clipboard@3.3.3:
version "3.3.3"
resolved "https://registry.yarnpkg.com/copy-to-clipboard/-/copy-to-clipboard-3.3.3.tgz#55ac43a1db8ae639a4bd99511c148cdd1b83a1b0"
integrity sha512-2KV8NhB5JqC3ky0r9PMCAZKbUHSwtEo4CwCs0KXgruG43gX5PMqDEBbVU4OUzw2MuAWUfsuFmWvEKG5QRfSnJA==
dependencies:
toggle-selection "^1.0.6"
core-js-compat@^3.38.0, core-js-compat@^3.38.1:
version "3.38.1"
resolved "https://registry.yarnpkg.com/core-js-compat/-/core-js-compat-3.38.1.tgz#2bc7a298746ca5a7bcb9c164bcb120f2ebc09a09"
@ -6694,6 +6701,11 @@ to-space-case@^1.0.0:
dependencies:
to-no-case "^1.0.0"
toggle-selection@^1.0.6:
version "1.0.6"
resolved "https://registry.yarnpkg.com/toggle-selection/-/toggle-selection-1.0.6.tgz#6e45b1263f2017fa0acc7d89d78b15b8bf77da32"
integrity sha512-BiZS+C1OS8g/q2RRbJmy59xpyghNBqrr6k5L/uKBGRsTfxmu3ffiRnd8mlGPUVayg8pvfi5urfnu8TU7DVOkLQ==
"tough-cookie@^2.3.3 || ^3.0.1 || ^4.0.0":
version "4.1.4"
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-4.1.4.tgz#945f1461b45b5a8c76821c33ea49c3ac192c1b36"

Loading…
Cancel
Save