Skip to content

Commit b353980

Browse files
committed
fix: copy button fallback for HTTP (non-HTTPS)
1 parent f09c2bc commit b353980

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

β€Žpackages/dashboard/src/pages/AgentDetail.tsxβ€Ž

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@ import { useParams, useNavigate } from 'react-router-dom';
33
import { getAgent, updateAgent, deleteAgent, getAgentConfig } from '../api/client.js';
44
import { useI18n } from '../i18n/index.js';
55

6+
function copyText(text: string) {
7+
if (navigator.clipboard?.writeText) {
8+
navigator.clipboard.writeText(text).catch(() => fallbackCopy(text));
9+
} else {
10+
fallbackCopy(text);
11+
}
12+
}
13+
function fallbackCopy(text: string) {
14+
const ta = document.createElement('textarea');
15+
ta.value = text;
16+
ta.style.cssText = 'position:fixed;left:-9999px';
17+
document.body.appendChild(ta);
18+
ta.select();
19+
document.execCommand('copy');
20+
document.body.removeChild(ta);
21+
}
22+
623
// ─── Provider & Model Presets (shared with Settings) ─────────────────────────
724

825
interface ProviderPreset {
@@ -85,7 +102,7 @@ function CodeSnippet({ title, code }: { title: string; code: string }) {
85102
const { t } = useI18n();
86103

87104
const handleCopy = () => {
88-
navigator.clipboard.writeText(code);
105+
copyText(code);
89106
setCopied(true);
90107
setTimeout(() => setCopied(false), 2000);
91108
};
@@ -118,7 +135,7 @@ function StepBlock({ step, title, description, code, children, isLast }: {
118135

119136
const handleCopy = () => {
120137
if (!code) return;
121-
navigator.clipboard.writeText(code);
138+
copyText(code);
122139
setCopied(true);
123140
setTimeout(() => setCopied(false), 2000);
124141
};

0 commit comments

Comments
Β (0)