forked from open-webui/open-webui
fix: safari copy link issue
This commit is contained in:
parent
b67f80f7a4
commit
a4083f43cb
3 changed files with 33 additions and 49 deletions
|
@ -187,7 +187,8 @@ export const generateInitialsImage = (name) => {
|
|||
return canvas.toDataURL();
|
||||
};
|
||||
|
||||
export const copyToClipboard = (text) => {
|
||||
export const copyToClipboard = async (text) => {
|
||||
let result = false;
|
||||
if (!navigator.clipboard) {
|
||||
const textArea = document.createElement('textarea');
|
||||
textArea.value = text;
|
||||
|
@ -205,21 +206,27 @@ export const copyToClipboard = (text) => {
|
|||
const successful = document.execCommand('copy');
|
||||
const msg = successful ? 'successful' : 'unsuccessful';
|
||||
console.log('Fallback: Copying text command was ' + msg);
|
||||
result = true;
|
||||
} catch (err) {
|
||||
console.error('Fallback: Oops, unable to copy', err);
|
||||
}
|
||||
|
||||
document.body.removeChild(textArea);
|
||||
return;
|
||||
return result;
|
||||
}
|
||||
navigator.clipboard.writeText(text).then(
|
||||
function () {
|
||||
|
||||
result = await navigator.clipboard
|
||||
.writeText(text)
|
||||
.then(() => {
|
||||
console.log('Async: Copying to clipboard was successful!');
|
||||
},
|
||||
function (err) {
|
||||
console.error('Async: Could not copy text: ', err);
|
||||
}
|
||||
);
|
||||
return true;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Async: Could not copy text: ', error);
|
||||
return false;
|
||||
});
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
export const compareVersion = (latest, current) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue