gitbutlerapp/gitbutler · warning
Clipboard access is unavailable.
Error message
Clipboard access is unavailable.
What it means
copyText falls back to document.execCommand("copy") (used because navigator.clipboard is unavailable in the webview/embedded context). execCommand returns false when the browser refuses the copy — no clipboard permission, no user gesture, or the deprecated API is blocked — and this error is thrown in response.
Solutions
- Call copyText only from a direct user interaction (click/keyboard handler) so execCommand runs inside the gesture.
- Prefer navigator.clipboard.writeText when available and keep execCommand only as fallback.
- In Tauri, enable the clipboard-manager plugin/permission for the webview.
- Show a fallback UI (selectable text or a 'copy failed' toast) instead of relying on silent success.
- Test in the exact webview build you ship — clipboard behavior differs per platform.
Example fix
// before
input.select();
const copied = document.execCommand("copy");
// after
if (navigator.clipboard?.writeText) {
await navigator.clipboard.writeText(text);
} else {
input.select();
const copied = document.execCommand("copy");
if (!copied) throw new Error("Clipboard access is unavailable.");
} Defensive patterns
Strategy: fallback
Validate before calling
function canCopy(): boolean {
return typeof navigator !== "undefined" &&
(!!navigator.clipboard?.writeText || (typeof document !== "undefined" && !!document.execCommand));
} Type guard
function hasAsyncClipboard(cb: unknown): cb is Clipboard {
return typeof cb === "object" && cb !== null && typeof (cb as Clipboard).writeText === "function";
} Try / catch
try {
await copyText(text);
} catch {
showToast("Copy failed — select the text manually.");
selectElementForManualCopy(target);
} Prevention
- Only trigger clipboard writes from direct user gestures.
- Use navigator.clipboard.writeText first; keep execCommand as last-resort fallback.
- Configure Tauri clipboard-manager permissions in the webview.
- Show visible feedback when copy fails rather than assuming success.
- Test clipboard behavior in the shipped webview on each target platform.
When it happens
Trigger: document.execCommand("copy") returns false: the copy happens outside a user-gesture stack, the webview denies clipboard write access, or the page is in a context where execCommand is disabled/deprecated.
Common situations: Running in a Tauri/WebView build without clipboard permission configured; triggering copy programmatically (not from a click); automated tests/headless environments where clipboard APIs are stubbed out; very old or locked-down embedded browsers.
Understand the failure class
Background: Permission denied / not authorized / 403 Forbidden: access-control rejections when the caller lacks the required role, grant, or ownership — this error's family across 18 libraries.
Related errors
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/f19ac6e19214ee5a.
Report an issue: GitHub.
Appendix: source
Thrown at packages/but-mcp-app/src/WorkspaceApp.tsx:217
timeStyle: "short",
}).format(date);
}
async function copyText(value: string): Promise<void> {
if (navigator.clipboard?.writeText) {
await navigator.clipboard.writeText(value);
return;
}
const input = document.createElement("textarea");
input.value = value;
input.style.position = "fixed";
input.style.opacity = "0";
document.body.appendChild(input);
input.select();
const copied = document.execCommand("copy");
input.remove();
if (!copied) throw new Error("Clipboard access is unavailable.");
}
function GraphSegment({ kind, status }: { kind: "branch" | "commit"; status: GraphStatus }) {
return (
<span className="graph-segment" data-status={status} aria-hidden="true">
<svg viewBox="0 0 16 28" fill="none">
{kind === "commit" ? (
<>
<path className="graph-rail" d="M8 0V11M8 17V28" />
<circle cx="8" cy="14" r="3.5" />
</>
) : (
<>
<path className="graph-rail" d="M8 0V28" />
<path d="M16 14H14C10.6863 14 8 16.6863 8 20" />
</>
)}
</svg>View on GitHub (pinned to 58e5313667)