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"""
|
js_code = f"""
|
||||||
<script>
|
<script>
|
||||||
async function copyToClipboard() {{
|
var textArea = document.createElement("textarea");
|
||||||
try {{
|
textArea.value = `{escaped_error_text}`;
|
||||||
const text = `{escaped_error_text}`;
|
document.body.appendChild(textArea);
|
||||||
await navigator.clipboard.writeText(text);
|
textArea.select();
|
||||||
return true;
|
try {{
|
||||||
}} catch (err) {{
|
document.execCommand('copy');
|
||||||
console.error('Failed to copy text: ', err);
|
textArea.remove();
|
||||||
return false;
|
window.parent.document.querySelector('iframe').contentWindow.postMessage({{copied: true}}, '*');
|
||||||
}}
|
}} catch (err) {{
|
||||||
|
console.error('Failed to copy text: ', err);
|
||||||
|
textArea.remove();
|
||||||
}}
|
}}
|
||||||
copyToClipboard();
|
|
||||||
</script>
|
</script>
|
||||||
|
<div id="result"></div>
|
||||||
"""
|
"""
|
||||||
st.components.v1.html(js_code, height=0)
|
st.components.v1.html(js_code, height=0)
|
||||||
st.success("✅ Error log copied to clipboard!")
|
st.success("✅ Error log copied to clipboard!")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user