paperclipai/paperclip · error

execCommand copy failed

Error message

execCommand copy failed

What it means

Legacy clipboard fallback failure: document.execCommand('copy') on the off-screen textarea returned false, meaning the browser refused the programmatic copy (permissions, non-user-gesture context, or detached DOM). The error lets the caller surface a manual-copy fallback; the modern navigator.clipboard path is preferred when available.

Source

Thrown at ui/src/lib/clipboard.ts:41

  // success — so keep the element simple and just push it off-screen.
  const textarea = document.createElement("textarea");
  textarea.value = text;
  textarea.setAttribute("aria-hidden", "true");
  textarea.tabIndex = -1;
  textarea.style.position = "fixed";
  textarea.style.top = "0";
  textarea.style.left = "-9999px";
  document.body.appendChild(textarea);

  const previouslyFocused = document.activeElement as (Element & {
    focus?: (options?: FocusOptions) => void;
  }) | null;
  try {
    textarea.focus({ preventScroll: true });
    textarea.select();
    textarea.setSelectionRange(0, text.length);
    const success = document.execCommand("copy");
    if (!success) throw new Error("execCommand copy failed");
  } finally {
    document.body.removeChild(textarea);
    if (previouslyFocused !== document.activeElement && typeof previouslyFocused?.focus === "function") {
      previouslyFocused.focus({ preventScroll: true });
    }
  }
}

View on GitHub (pinned to 120ae5428f)

Solutions

  1. Use the async Clipboard API (navigator.clipboard.writeText) instead of execCommand, or retry after a user gesture grants clipboard permission.
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at ui/src/lib/clipboard.ts:41 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of paperclipai/paperclip@120ae5428f (2026-08-18). Data as JSON: /api/errors/f27e781797ac3499. Report an issue: GitHub.