You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am attempting to create a button that copies some text to the user's clipboard. I have included a simplified version of the relevant code below:
put_scope("example_scope")
with use_scope("example_scope):
put_button('Copy', onclick=example_copy_callback)
def example_copy_callback() -> None:
text_to_copy = "Hello World"
run_js("""navigator.clipboard.writeText(out).then(
() => {
console.log('Content copied to clipboard');
}, (err) => {
console.error('Failed to copy: ', err);
});""", out = text_to_copy
)
This is working in both Chrome and Firefox, however with Safari I am getting the following error: Failed to copy: – NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.
I believe this has something to do with the fact that in Safari, clipboard.writeText() must be called within user gesture event handlers such as pointerdown or pointerup (source). Unfortunately, I am a noob when it comes to javascript and web development, and I am not clear on how this detail would interact with the underlying onclick callback and run_js() method of PyWebIO.
Any insight into why this is failing or viable workarounds would be greatly appreciated!
The text was updated successfully, but these errors were encountered:
I considered using a similar approach but was hesitant because document.execCommand is deprecated and no longer recommended. It looks like all major browsers still support it for backwards compatibility, so maybe this is an appropriate workaround for the time being.
Hello,
I am attempting to create a button that copies some text to the user's clipboard. I have included a simplified version of the relevant code below:
This is working in both Chrome and Firefox, however with Safari I am getting the following error:
Failed to copy: – NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.
I believe this has something to do with the fact that in Safari,
clipboard.writeText()
must be called within user gesture event handlers such as pointerdown or pointerup (source). Unfortunately, I am a noob when it comes to javascript and web development, and I am not clear on how this detail would interact with the underlyingonclick
callback andrun_js()
method of PyWebIO.Any insight into why this is failing or viable workarounds would be greatly appreciated!
The text was updated successfully, but these errors were encountered: