Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
fix(open-knowledge): embedded-host copy-prompt clipboard fallback (#1956)
sarahad421cd1186a
diff --git a/.changeset/embedded-copy-prompt-clipboard.md b/.changeset/embedded-copy-prompt-clipboard.mdnew file mode 100644index 000000000..0937de6cf--- /dev/null+++ b/.changeset/embedded-copy-prompt-clipboard.md@@ -0,0 +1,5 @@+---+"@inkeep/open-knowledge": patch+---++Fix the empty-state "copy prompt" rows not working when OK runs inside an embedded host iframe (e.g. Claude). The copy buttons called the async Clipboard API directly, which the host frame's Permissions-Policy refuses inside an iframe — the rejection was swallowed silently, so nothing copied and the row never showed "Copied". The copy now routes through the shared clipboard adapter, whose `execCommand` fallback succeeds under the click's user activation where the policy-gated async write is blocked.diff --git a/packages/app/src/components/empty-state/CopyablePromptList.dom.test.tsx b/packages/app/src/components/empty-state/CopyablePromptList.dom.test.tsxnew file mode 100644index 000000000..2506ce820--- /dev/null+++ b/packages/app/src/components/empty-state/CopyablePromptList.dom.test.tsx@@ -0,0 +1,100 @@+import { afterEach, beforeEach, describe, expect, mock, test } from 'bun:test';+import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';+import type { ReactNode } from 'react';+import { renderLinguiTemplate } from '@/test-utils/lingui-mock';++mock.module('@lingui/react/macro', () => ({+ Trans: ({ children }: { children?: ReactNode }) => <>{children}</>,+ useLingui: () => ({ t: renderLinguiTemplate }),+}));++const { CopyablePromptList } = await import('./CopyablePromptList');++describe('CopyablePromptList', () => {+ beforeEach(() => {+ Reflect.deleteProperty(globalThis, 'okDesktop');+ Object.defineProperty(globalThis.navigator, 'clipboard', {+ configurable: true,+ value: undefined,+ });+ });+ afterEach(() => {+ cleanup();+ Reflect.deleteProperty(globalThis.document, 'execCommand');+ });++ test('flips a row to "Copied" when the clipboard write resolves', async () => {+ const writeText = mock(() => Promise.resolve());+ Object.defineProperty(globalThis.navigator, 'clipboard', {+ configurable: true,+ value: { writeText },+ });++ render(<CopyablePromptList scenario="new-project" />);++ const button = screen.getByTestId('copy-prompt-button-competitor-research');+ fireEvent.click(button);++ await waitFor(() => {+ expect(screen.getByTestId('copy-prompt-button-competitor-research').textContent).toContain(+ 'Copied',+ );+ });+ expect(writeText).toHaveBeenCalledTimes(1);+ });++ test('falls back to execCommand and still copies when embedded-iframe policy refuses the async write', async () => {+ const writeText = mock(() =>+ Promise.reject(+ Object.assign(new Error('blocked because of a permissions policy'), {+ name: 'NotAllowedError',+ }),+ ),+ );+ Object.defineProperty(globalThis.navigator, 'clipboard', {+ configurable: true,+ value: { writeText },+ });+ const execCommand = mock(() => true);+ Object.defineProperty(globalThis.document, 'execCommand', {+ configurable: true,+ value: execCommand,+ });++ render(<CopyablePromptList scenario="new-project" />);++ fireEvent.click(screen.getByTestId('copy-prompt-button-competitor-research'));++ await waitFor(() => {+ expect(screen.getByTestId('copy-prompt-button-competitor-research').textContent).toContain(+ 'Copied',+ );+ });+ expect(writeText).toHaveBeenCalledTimes(1);+ expect(execCommand).toHaveBeenCalledWith('copy');+ });++ test('does not flip to "Copied" when every clipboard path is refused', async () => {+ const writeText = mock(() =>+ Promise.reject(Object.assign(new Error('blocked'), { name: 'NotAllowedError' })),+ );+ Object.defineProperty(globalThis.navigator, 'clipboard', {+ configurable: true,+ value: { writeText },+ });+ const execCommand = mock(() => false);+ Object.defineProperty(globalThis.document, 'execCommand', {+ configurable: true,+ value: execCommand,+ });++ render(<CopyablePromptList scenario="new-project" />);+ fireEvent.click(screen.getByTestId('copy-prompt-button-competitor-research'));++ await waitFor(() => expect(execCommand).toHaveBeenCalledWith('copy'));+ expect(writeText).toHaveBeenCalledTimes(1);+ expect(screen.getByTestId('copy-prompt-button-competitor-research').textContent).not.toContain(+ 'Copied',+ );+ });+});diff --git a/packages/app/src/components/empty-state/CopyablePromptList.tsx b/packages/app/src/components/empty-state/CopyablePromptList.tsxindex 7c72dacd8..49ec9d01d 100644--- a/packages/app/src/components/empty-state/CopyablePromptList.tsx+++ b/packages/app/src/components/empty-state/CopyablePromptList.tsx@@ -6,6 +6,7 @@ import {useCreateSuggestions,} from '@/components/empty-state/use-create-suggestions';import { Button } from '@/components/ui/button';+import { scheduleClipboardWrite } from '@/lib/share/clipboard-adapter';import { cn } from '@/lib/utils';interface CopyablePromptListProps {@@ -22,9 +23,7 @@ export function CopyablePromptList({ scenario, className }: CopyablePromptListPruseEffect(() => () => clearTimeout(resetTimerRef.current), []);function handleCopy(id: string, prompt: string) {- if (!navigator.clipboard) return;- void navigator.clipboard- .writeText(prompt)+ void scheduleClipboardWrite(prompt).then(() => {setCopiedId(id);clearTimeout(resetTimerRef.current);