> For the complete documentation index, see [llms.txt](https://developers-apps-in-toss.toss.im/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers-apps-in-toss.toss.im/documentation/api-and-sdk-en/common/permission/clipboard.md).

# Clipboard

{% hint style="info" %}
**Permission settings are required**

`getClipboardText`You must set clipboard permissions before using it. Please check the permission setup guide first.
{% endhint %}

***

### 1. Get clipboard text

**SDK function:** `getClipboardText`

A function that reads the text stored in the clipboard.

**Signature**

```typescript
function getClipboardText(): Promise<string>;
```

**Return value**

* `Promise<string>`

  Returns the text stored in the clipboard. If there is no text in the clipboard, returns an empty string.

**Permission methods**

* getClipboardText.getPermission

  Returns the current status of clipboard read permission. `allowed` · `denied` · `notDetermined` · `osPermissionDenied` returns one of
* getClipboardText.openPermissionDialog

  Shows a dialog to request clipboard read permission again. If allowed, `allowed`, if denied `denied`is returned.

**Error**

If permission is denied `GetClipboardTextPermissionError`occurs. `error instanceof GetClipboardTextPermissionError`You can check it with

```typescript
class GetClipboardTextPermissionError extends PermissionError {
  constructor();
}
```

**Example**

{% tabs %}
{% tab title="Web (JS)" %}

```js
import { getClipboardText, GetClipboardTextPermissionError } from '@apps-in-toss/web-framework';

async function handleGetClipboardText() {
  try {
    const clipboardText = await getClipboardText();
    console.log('Clipboard text:', clipboardText || 'There is no text in the clipboard.');
  } catch (error) {
    if (error instanceof GetClipboardTextPermissionError) {
      console.log('No clipboard read permission');
    }
  }
}
```

{% endtab %}

{% tab title="Web (React)" %}

```tsx
import { getClipboardText, GetClipboardTextPermissionError } from '@apps-in-toss/web-framework';
import { useState } from 'react';

function PasteButton() {
  const [text, setText] = useState('');

  const handlePress = async () => {
    try {
      const clipboardText = await getClipboardText();
      setText(clipboardText || 'There is no text in the clipboard.');
    } catch (error) {
      if (error instanceof GetClipboardTextPermissionError) {
        // No clipboard read permission
      }
    }
  };

  return (
    <div>
      <span>{text}</span>
      <input type="button" value="Paste" onClick={handlePress} />
      <input
        type="button"
        value="Check permission"
        onClick={async () => {
          const permission = await getClipboardText.getPermission();
          alert(permission);
        }}
      />
      <input
        type="button"
        value="Request permission"
        onClick={async () => {
          const permission = await getClipboardText.openPermissionDialog();
          alert(permission);
        }}
      />

  );
}
```

{% endtab %}

{% tab title="React Native" %}

```tsx
import { getClipboardText, GetClipboardTextPermissionError } from '@apps-in-toss/framework';
import { useState } from 'react';
import { Alert, Button, Text, View } from 'react-native';

function PasteButton() {
  const [text, setText] = useState('');

  const handlePress = async () => {
    try {
      const clipboardText = await getClipboardText();
      setText(clipboardText || 'There is no text in the clipboard.');
    } catch (error) {
      if (error instanceof GetClipboardTextPermissionError) {
        // No clipboard read permission
      }
    }
  };

  return (
    <View>
      <Text>{text}</Text>
      <Button title="Paste" onPress={handlePress} />
      <Button
        title="Check Permission"
        onPress={async () => {
          const permission = await getClipboardText.getPermission();
          Alert.alert(permission);
        }}
      />
      <Button
        title="Request permission"
        onPress={async () => {
          const permission = await getClipboardText.openPermissionDialog();
          Alert.alert(permission);
        }}
      />
    </View>
  );
}
```

{% endtab %}
{% endtabs %}

***

### 2. Copy clipboard text

**SDK function:** `setClipboardText`

A function that copies text to the clipboard. The user can paste it elsewhere.

**Signature**

```typescript
function setClipboardText(text: string): Promise<void>;
```

**Parameters**

* **text** · Required · `string`

  The text to copy to the clipboard.

**Permission methods**

* setClipboardText.getPermission

  Returns the current status of clipboard write permission. `allowed` · `denied` · `notDetermined` · `osPermissionDenied` returns one of
* setClipboardText.openPermissionDialog

  Shows a dialog to request clipboard write permission again. If allowed, `allowed`, if denied `denied`is returned.

**Error**

If permission is denied `SetClipboardTextPermissionError`occurs. `error instanceof SetClipboardTextPermissionError`You can check it with

```typescript
class SetClipboardTextPermissionError extends PermissionError {
  constructor();
}
```

**Example**

{% tabs %}
{% tab title="Web (JS)" %}

```js
import { setClipboardText, SetClipboardTextPermissionError } from '@apps-in-toss/web-framework';

async function handleSetClipboardText() {
  try {
    await setClipboardText('Text to copy');
    console.log('The text has been copied!');
  } catch (error) {
    if (error instanceof SetClipboardTextPermissionError) {
      console.log('No clipboard write permission');
    }
  }
}
```

{% endtab %}

{% tab title="Web (React)" %}

```tsx
import { setClipboardText, SetClipboardTextPermissionError } from '@apps-in-toss/web-framework';

function CopyButton() {
  const handleCopy = async () => {
    try {
      await setClipboardText('Text to copy');
      console.log('The text has been copied!');
    } catch (error) {
      if (error instanceof SetClipboardTextPermissionError) {
        // No clipboard write permission
      }
    }
  };

  return (
    <>
      <input type="button" value="Copy" onClick={handleCopy} />
      <input
        type="button"
        value="Check permission"
        onClick={async () => {
          const permission = await setClipboardText.getPermission();
          alert(permission);
        }}
      />
      <input
        type="button"
        value="Request permission"
        onClick={async () => {
          const permission = await setClipboardText.openPermissionDialog();
          alert(permission);
        }}
      />
    </>
  );
}
```

{% endtab %}

{% tab title="React Native" %}

```tsx
import { setClipboardText, SetClipboardTextPermissionError } from '@apps-in-toss/framework';
import { Alert, Button } from 'react-native';

function CopyButton() {
  const handleCopy = async () => {
    try {
      await setClipboardText('Text to copy');
      console.log('The text has been copied!');
    } catch (error) {
      if (error instanceof SetClipboardTextPermissionError) {
        // No clipboard write permission
      }
    }
  };

  return (
    <>
      <Button title="Copy" onPress={handleCopy} />
      <Button
        title="Check Permission"
        onPress={async () => {
          const permission = await setClipboardText.getPermission();
          Alert.alert(permission);
        }}
      />
      <Button
        title="Request permission"
        onPress={async () => {
          const permission = await setClipboardText.openPermissionDialog();
          Alert.alert(permission);
        }}
      />
    </>
  );
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://developers-apps-in-toss.toss.im/documentation/api-and-sdk-en/common/permission/clipboard.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
