refactor: Replace async clipboard method with more reliable execCommand approach
This commit is contained in:
parent
08c116b2a9
commit
02c03e08c8
@ -531,18 +531,20 @@ if st.session_state.error_log:
|
||||
|
||||
js_code = f"""
|
||||
<script>
|
||||
async function copyToClipboard() {{
|
||||
try {{
|
||||
const text = `{escaped_error_text}`;
|
||||
await navigator.clipboard.writeText(text);
|
||||
return true;
|
||||
}} catch (err) {{
|
||||
console.error('Failed to copy text: ', err);
|
||||
return false;
|
||||
}}
|
||||
var textArea = document.createElement("textarea");
|
||||
textArea.value = `{escaped_error_text}`;
|
||||
document.body.appendChild(textArea);
|
||||
textArea.select();
|
||||
try {{
|
||||
document.execCommand('copy');
|
||||
textArea.remove();
|
||||
window.parent.document.querySelector('iframe').contentWindow.postMessage({{copied: true}}, '*');
|
||||
}} catch (err) {{
|
||||
console.error('Failed to copy text: ', err);
|
||||
textArea.remove();
|
||||
}}
|
||||
copyToClipboard();
|
||||
</script>
|
||||
<div id="result"></div>
|
||||
"""
|
||||
st.components.v1.html(js_code, height=0)
|
||||
st.success("✅ Error log copied to clipboard!")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user