refactor: Update clipboard copy method to use modern Clipboard API

This commit is contained in:
Bobby Abellana (aider) 2025-02-18 09:46:19 -08:00
parent 48f03f89f9
commit 08c116b2a9

View File

@ -531,17 +531,17 @@ if st.session_state.error_log:
js_code = f""" js_code = f"""
<script> <script>
// Create a temporary textarea element async function copyToClipboard() {{
const textarea = document.createElement('textarea'); try {{
textarea.value = `{escaped_error_text}`; const text = `{escaped_error_text}`;
document.body.appendChild(textarea); await navigator.clipboard.writeText(text);
return true;
// Select and copy the text }} catch (err) {{
textarea.select(); console.error('Failed to copy text: ', err);
document.execCommand('copy'); return false;
}}
// Clean up }}
document.body.removeChild(textarea); copyToClipboard();
</script> </script>
""" """
st.components.v1.html(js_code, height=0) st.components.v1.html(js_code, height=0)