Skip to content

Fix Safari NotAllowedError when generating a public sharing link#3767

Draft
Copilot wants to merge 1 commit intomasterfrom
copilot/fix-safari-clipboard-error
Draft

Fix Safari NotAllowedError when generating a public sharing link#3767
Copilot wants to merge 1 commit intomasterfrom
copilot/fix-safari-clipboard-error

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 26, 2026

Safari blocks navigator.clipboard.writeText() with NotAllowedError when it is called after an await in an event handler, because the user-gesture context is lost across the async boundary. In ShareRestrictionModal, the clipboard write happened after await createPermissions(...), so it always failed on the first click in Safari.

Changes (cozy-sharingpackages/cozy-sharing/src/components/ShareRestrictionModal/)

  • ShareRestrictionModal.jsx — restructure handleClick to build a Promise<Blob> for the URL without awaiting it first, then pass that promise directly to copyToClipboard. The clipboard API call is now initiated synchronously within the click handler; only the content resolution is async.

  • helpers.js — extend copyToClipboard to accept string | Promise<Blob>. When a Promise<Blob> is received and ClipboardItem is available, use navigator.clipboard.write([new ClipboardItem({...})]) instead of writeText. Safari supports this pattern: the permission check happens at call time (synchronous, within the gesture), the blob is consumed when the promise resolves.

// Before — clipboard write happens after an async gap; fails in Safari
const { data: perms } = await createPermissions(...)   // ← async gap
const url = generateWebLink(...)
await copyToClipboard(url, { t, showAlert })            // ← NotAllowedError

// After — clipboard write initiated synchronously; content resolved async
const urlBlobPromise = createPermissions(...).then(({ data: perms }) => {
  const url = generateWebLink(...)
  return new Blob([url], { type: 'text/plain' })
})
await copyToClipboard(urlBlobPromise, { t, showAlert }) // ← ClipboardItem + Promise

These changes belong in linagora/cozy-libs. The fix is fully specified here; a developer needs to apply it there and cut a new cozy-sharing release, after which twake-drive can bump its dependency.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • errors.cozycloud.cc
    • Triggering command: `/opt/hostedtoolcache/node/24.14.0/x64/bin/node /opt/hostedtoolcache/node/24.14.0/x64/bin/node /home/REDACTED/work/twake-drive/twake-drive/node_modules/jest-worker/build/processChild.js mponents/FolderP--ignore-engines mponents/FolderPconntrack mpon�� mponents/FolderPINVALID,NEW mponents/FolderP-j ake-drive/src/coDROP ally
      pkg['devDependencies'] = dict(sorted(pkg['devDependencies'].items()))

with open('package. ake-drive/src/coadd ake-drive/src/co-f ake-drive/src/conode_modules/cozy-sharing ake-�� d.*copy ake-drive/src/components/FileHistory/HistoryModal.jsx` (dns block)

  • Triggering command: /opt/hostedtoolcache/node/24.14.0/x64/bin/node /opt/hostedtoolcache/node/24.14.0/x64/bin/node /home/REDACTED/work/twake-drive/twake-drive/node_modules/jest-worker/build/processChild.js mponents/FolderP--ignore-engines mponents/FolderPconntrack mpon�� mponents/FolderPINVALID,NEW mponents/FolderP-j modules/@npmcli/run-script/lib/node-gyp-bin/git ake-drive/src/cogit ake-drive/src/coadd ake-drive/src/co-f ake-drive/src/conode_modules/cozy-sharing ake-�� d.*copy ake-drive/src/components/FileHistory/HistoryModal.jsx de ake-drive/src/cobash ake-drive/src/co--norc ake-drive/src/co--noprofile ake-drive/src/components/Button/security (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Bug with Safari : Error snackbar after public sharing link creation</issue_title>
<issue_description>On safari when I click on generate a link, I got an error with the clipboard.

But after the first error, when I click on copy it works.

Here is the error:

ShareRestrictionModal/helpers"error""Error in 'copyToClipboard' function when trying to copy to clipboard"
NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission. — 

https://github.com/user-attachments/assets/9cda282f-afc4-4e59-b079-cb8278e62024</issue_description>

<agent_instructions>Explain me why this error happened base on the code you can read. And please suggest me a fix. </agent_instructions>

Comments on the Issue (you are @copilot in this section)


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Copy link
Copy Markdown

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No application code in the PR — skipped Code Health checks.

See analysis details in CodeScene

Quality Gate Profile: The Bare Minimum
Install CodeScene MCP: safeguard and uplift AI-generated code. Catch issues early with our IDE extension and CLI tool.

Copilot AI changed the title [WIP] Fix clipboard error on Safari after link generation Fix Safari NotAllowedError when generating a public sharing link Mar 26, 2026
Copilot AI requested a review from Crash-- March 26, 2026 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug with Safari : Error snackbar after public sharing link creation

2 participants