Before you start
- The exact string to copy, separate from decorative line numbers.
- A secure browser context for the Clipboard API.
- A visible status region for feedback.
How to do it
- Choose the source text and keep formatting characters that the user actually needs.
- Call navigator.clipboard.writeText in response to a user click and await the result.
- Show success only after the promise resolves. Offer selection and manual copying when it fails.
- Paste into a plain-text editor to check quotes, line breaks, and completeness.
Before & after
try {
await navigator.clipboard.writeText(text);
status.textContent = "Copied.";
} catch {
status.textContent = "Select the text and copy it manually.";
}The intended text reaches the clipboard, or the user gets a usable fallback instead of a false success message.
Use with an AI coding tool
1 Describe your change
Use your own words. You do not need a file name. The prompt asks the AI to preserve unrelated work.
We remember this choice on this device. Choosing a tool does not connect it to this website.
2 Copy your prompt
Read the complete prompt below, then copy it.
3 Paste into your AI coding tool
Open your website or app project in your AI coding tool. Paste this into its AI chat box and send it. The tool needs access to your project files to make changes.
A website address alone does not give an AI permission or access to edit it. This prompt goes into an AI chat, not a regular terminal window.
4 Check the result
Check exact copied content and a fallback when clipboard access is unavailable.
Open your project preview and try the change. Review what changed before publishing. If it is wrong, use your tool’s undo or restore your saved project version.
If the result is not what you expected
Copy fails on an insecure page
Clipboard writing requires a secure context in supporting browsers. Test on HTTPS.
Only part of a command is copied
Use the underlying complete string, not truncated visible card text.
Undo the change
Remove the copy handler and keep the text selectable so the page remains useful.
References & testing
The examples above explain the expected behavior; they are not a claim that this prompt has been tested in every framework or AI model. Test the proposed change in your actual project before publishing.