fix(share): only copy to clipboard if available and secure

This commit is contained in:
Kendall Garner
2026-02-19 19:55:10 -08:00
parent ab9e02adfc
commit 0741351318
2 changed files with 16 additions and 5 deletions
+2
View File
@@ -391,9 +391,11 @@
},
"shareItem": {
"allowDownloading": "allow downloading",
"copyToClipboard": "Copy to clipboard: Ctrl+C, Enter",
"description": "description",
"setExpiration": "set expiration",
"success": "share link copied to clipboard (or click here to open)",
"successMustClick": "share created successfully. click here to open",
"expireInvalid": "expiration must be in the future",
"createFailed": "failed to create share (is sharing enabled?)"
},
@@ -74,13 +74,22 @@ export const ShareItemContextModal = ({
if (!serverUrl) throw new Error('Server URL not found');
const shareUrl = `${serverUrl}/share/${_data.id}`;
navigator.clipboard.writeText(shareUrl);
const canUseClipboard = navigator.clipboard && window.isSecureContext;
if (canUseClipboard) {
navigator.clipboard.writeText(shareUrl);
}
toast.success({
autoClose: 5000,
autoClose: canUseClipboard ? 5000 : 15000,
id: 'share-item-toast',
message: t('form.shareItem.success', {
postProcess: 'sentenceCase',
}),
message: t(
canUseClipboard
? 'form.shareItem.success'
: 'form.shareItem.successMustClick',
{
postProcess: 'sentenceCase',
},
),
onClick: (a) => {
if (!(a.target instanceof HTMLElement)) return;