{"record":{"id":"f19ac6e19214ee5a","repo":"gitbutlerapp/gitbutler","slug":"clipboard-access-is-unavailable","errorCode":null,"errorMessage":"Clipboard access is unavailable.","messagePattern":"Clipboard access is unavailable\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/but-mcp-app/src/WorkspaceApp.tsx","lineNumber":217,"sourceCode":"\t\ttimeStyle: \"short\",\n\t}).format(date);\n}\n\nasync function copyText(value: string): Promise<void> {\n\tif (navigator.clipboard?.writeText) {\n\t\tawait navigator.clipboard.writeText(value);\n\t\treturn;\n\t}\n\n\tconst input = document.createElement(\"textarea\");\n\tinput.value = value;\n\tinput.style.position = \"fixed\";\n\tinput.style.opacity = \"0\";\n\tdocument.body.appendChild(input);\n\tinput.select();\n\tconst copied = document.execCommand(\"copy\");\n\tinput.remove();\n\tif (!copied) throw new Error(\"Clipboard access is unavailable.\");\n}\n\nfunction GraphSegment({ kind, status }: { kind: \"branch\" | \"commit\"; status: GraphStatus }) {\n\treturn (\n\t\t<span className=\"graph-segment\" data-status={status} aria-hidden=\"true\">\n\t\t\t<svg viewBox=\"0 0 16 28\" fill=\"none\">\n\t\t\t\t{kind === \"commit\" ? (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<path className=\"graph-rail\" d=\"M8 0V11M8 17V28\" />\n\t\t\t\t\t\t<circle cx=\"8\" cy=\"14\" r=\"3.5\" />\n\t\t\t\t\t</>\n\t\t\t\t) : (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<path className=\"graph-rail\" d=\"M8 0V28\" />\n\t\t\t\t\t\t<path d=\"M16 14H14C10.6863 14 8 16.6863 8 20\" />\n\t\t\t\t\t</>\n\t\t\t\t)}\n\t\t\t</svg>","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/packages/but-mcp-app/src/WorkspaceApp.tsx#L199-L235","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\ninput.select();\nconst copied = document.execCommand(\"copy\");\n// after\nif (navigator.clipboard?.writeText) {\n  await navigator.clipboard.writeText(text);\n} else {\n  input.select();\n  const copied = document.execCommand(\"copy\");\n  if (!copied) throw new Error(\"Clipboard access is unavailable.\");\n}","handlingStrategy":"fallback","validationCode":"function canCopy(): boolean {\n  return typeof navigator !== \"undefined\" &&\n    (!!navigator.clipboard?.writeText || (typeof document !== \"undefined\" && !!document.execCommand));\n}","typeGuard":"function hasAsyncClipboard(cb: unknown): cb is Clipboard {\n  return typeof cb === \"object\" && cb !== null && typeof (cb as Clipboard).writeText === \"function\";\n}","tryCatchPattern":"try {\n  await copyText(text);\n} catch {\n  showToast(\"Copy failed — select the text manually.\");\n  selectElementForManualCopy(target);\n}","preventionTips":["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."],"tags":["clipboard","browser-api","deprecated"],"backgroundTag":"permission-denied","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}