fixed logs clipboard data copy

This commit is contained in:
Gani Georgiev
2025-03-25 22:12:43 +02:00
parent ffc848e92d
commit 81cc276ab9
30 changed files with 49 additions and 43 deletions
+12 -6
View File
@@ -847,19 +847,25 @@ export default class CommonHelper {
}
/**
* Copies text to the user clipboard.
* Serializes the provided data and copies the resulting text into the user clipboard.
*
* @param {String} text
* @param {Mixed} data
* @return {Promise}
*/
static async copyToClipboard(text) {
text = "" + text // ensure that text is string
static async copyToClipboard(data) {
if (typeof data === "object") {
try {
data = JSON.stringify(data, null, 2)
} catch {}
}
if (!text.length || !window?.navigator?.clipboard) {
data = "" + data // ensure that data is string
if (!data.length || !window?.navigator?.clipboard) {
return;
}
return window.navigator.clipboard.writeText(text).catch((err) => {
return window.navigator.clipboard.writeText(data).catch((err) => {
console.warn("Failed to copy.", err);
})
}