Copy buttons fail in Safari: Studio calls navigator.clipboard.write() with no fallback to writeText()
Summary
Every Copy button in Studio fails in Safari with the toast "Unable to copy to clipboard". On the affected Safari, navigator.clipboard.write() rejects with NotAllowedError while navigator.clipboard.writeText() works normally. Studio has at least two independent copy paths and both commit to write() without ever falling back to writeText().
Environment
| Browser | Safari 27.0 |
| OS | macOS 26 (build 26A428), Apple Silicon |
| Studio commit | 05a45dd1edbaeb972d960e181b18cb4878b49674 (2026-09-22T22:52:07Z) |
| Safari extensions | none enabled |
| Lockdown Mode | off |
| Chrome, same machine | works |
| Other sites in Safari (GitHub copy buttons) | work — they use writeText() |
Steps to reproduce
- Open Safari.
- Go to Project Settings → API Keys → Legacy anon, service_role API keys.
- Click any Copy button.
Expected: key is copied. Actual: toast "Unable to copy to clipboard". Nothing reaches the clipboard.
NotAllowedError: The request is not allowed by the user agent or the platform in the current context,
possibly because the user denied permission.
write
(anonymous function) — 1hdqq-u-k_pkz.js:10:21436
onClick — 1hdqq-u-k_pkz.js:10:7873Clicking directly on the key field (instead of the Copy button) produces a second, different stack — from Studio's Monaco/VS Code-derived clipboard service:
Unhandled Promise Rejection: Canceled: Canceled
(anonymous function) — async.ts:744
Promise
error — async.ts:743
g — clipboardService.ts:68
ERR
NotAllowedError: The request is not allowed by the user agent or the platform in the current context,
possibly because the user denied permission.
write
g — clipboardService.ts:76Two independent copy paths, different code, same failure: both call navigator.clipboard.write(), neither falls back to writeText().
The user's machine is not the problem
Ruled out with an NSPasteboard.changeCount monitor running on the affected Mac while the user reproduced the bug. Every line below is a real clipboard write captured live:
[21:07:56] 7->8 Safari 164 chars webarchive/rtf <- Cmd+C on an unrelated page: works
[21:08:52] 8->9 Safari 211 chars public.utf8-plain-text <- Cmd+C on text FROM THIS SAME PAGE: works
[21:09:23] 9->10 Safari (no text) public.png <- screenshot to clipboard: worksBetween 21:08:52 and 21:09:23 the user clicked the key field and pressed Cmd+C: no pasteboard write was recorded at all.
So on this machine the system pasteboard is healthy, Safari's native Cmd+C works, it works on the very page that fails, and images copy fine. Also ruled out: Lockdown Mode (off), Safari extensions (none), per-site clipboard settings (none), managed policies (none), and any other process contending for the pasteboard (a separate 20s monitor recorded zero spontaneous writes).
The only thing that fails is Studio's own copy paths.
Minimal reproduction
Paste into the Safari console on any Studio page, then click each button separately (WebKit allows one clipboard write per user gesture):
[['A writeText','#c00',()=>navigator.clipboard.writeText('A')],
['B Blob direct','#070',()=>navigator.clipboard.write([new ClipboardItem({'text/plain':new Blob(['B'],{type:'text/plain'})})])],
['C Blob in promise','#00c',()=>navigator.clipboard.write([new ClipboardItem({'text/plain':Promise.resolve('C').then(t=>new Blob([t],{type:'text/plain'}))})])]
].forEach(([n,bg,fn],i)=>{const b=document.createElement('button');b.textContent=n;
b.style.cssText=`position:fixed;z-index:99999;top:${10+i*44}px;left:10px;padding:10px 16px;background:${bg};color:#fff;font-size:15px;border:0;border-radius:6px`;
b.onclick=async()=>{try{await fn();console.log('OK '+n)}catch(e){console.log('FAIL '+n+': '+e.name+' — '+e.message)}};
document.body.appendChild(b)});Results on the affected machine:
| Variant | API | Result |
|---|---|---|
| A | navigator.clipboard.writeText(str) |
OK |
| B | navigator.clipboard.write([ClipboardItem]), Blob passed directly |
NotAllowedError |
| C | navigator.clipboard.write([ClipboardItem]), Blob wrapped in a Promise |
NotAllowedError |
Each button is freshly created, has a direct onclick, and performs exactly one clipboard write per gesture. So this is not lost user activation, and not the promise wrapper. navigator.clipboard.write() itself is rejected by this Safari; writeText() is not.
Root cause
packages/ui/src/lib/utils/clipboard.ts (identical on master and on the deployed commit):
try {
if (typeof ClipboardItem !== 'undefined' && navigator.clipboard?.write) {
const text = new ClipboardItem({
'text/plain': Promise.resolve(str).then((text) => new Blob([text], { type: 'text/plain' })),
})
await navigator.clipboard.write([text])
callback()
return
}
if (!navigator.clipboard) throw new Error('Clipboard API unavailable')
await Promise.resolve(str).then((text) => navigator.clipboard.writeText(text))
callback()
} catch {
toast.error('Unable to copy to clipboard')
}The branch is chosen by whether navigator.clipboard.write exists, not by whether it works. Safari exposes it, so the write path is always taken there, and the early return makes the writeText path below dead code for Safari. When write() rejects, control goes straight to the catch and the user gets the toast — even though writeText() succeeds on the same page, in the same gesture.
The write([ClipboardItem]) path exists to support Promise<string> inputs in Safari, per the comments in the file. That need is real. The bug is that the path has no fallback.
Suggested fix
try {
if (typeof ClipboardItem !== 'undefined' && navigator.clipboard?.write) {
try {
const text = new ClipboardItem({
'text/plain': Promise.resolve(str).then((text) => new Blob([text], { type: 'text/plain' })),
})
await navigator.clipboard.write([text])
callback()
return
} catch {
// Safari can expose clipboard.write() and still reject it. Fall through to writeText().
}
}
if (!navigator.clipboard) throw new Error('Clipboard API unavailable')
await Promise.resolve(str).then((text) => navigator.clipboard.writeText(text))
callback()
} catch {
toast.error('Unable to copy to clipboard')
}Note on the Safari caveat documented in the file: awaiting the str promise before writeText() can lose user activation in Safari. That only matters for callers passing a Promise<string>. For a plain string — which is what ui-patterns/src/DataInputs/Input.tsx passes via _onCopy for every Copy button in Studio — Promise.resolve(str) settles in a microtask within the same task, so activation is intact. If the distinction matters, gate the fallback on typeof str === 'string'.
The Monaco-derived path behind clipboardService.ts needs the same treatment.
Secondary finding: Safari AutoFill-generated passwords cannot be copied either
Separate mechanism, same user-visible symptom, different dialog.
On Database → Settings → Reset database password:
- Password generated by Safari's own strong-password AutoFill → Copy fails with the same
NotAllowedError/clipboardService.ts:76stack. - Password generated by Supabase's own "Generate a password" link → Copy works.
Likely cause: WebKit withholds AutoFilled password-field values from page JavaScript until the user manually interacts with the field — an anti-exfiltration protection. Studio's copy handler reads input.value, gets nothing usable, and the clipboard call fails. When Studio itself sets the value, there is no AutoFill protection and the copy succeeds.
Worth handling explicitly: if the value read back from a password field is empty or the clipboard write fails, the UI should say so rather than emitting a generic "Unable to copy to clipboard", since the user can see a filled field and has no way to guess why.
Not investigated
Why this Safari rejects navigator.clipboard.write() at all. That is a WebKit question, possibly specific to Safari 27 / macOS 26. Worth filing separately with Apple. The Studio-side fix is independent of the answer: any write() failure, from any cause, should degrade to writeText() rather than to an error toast.
Source: supabase/supabase