-
Notifications
You must be signed in to change notification settings - Fork 388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
In Safari Clipboard.WriteText() does not work in a button on_click callback #561
Comments
I failed to set clipboard via However, I use a more compatible code to set clipboard in the pywebio's demo in document (like this). CLIPBOARD_SETUP = """
window.writeText = function(text) {
const input = document.createElement('textarea');
input.style.opacity = 0;
input.style.position = 'absolute';
input.style.left = '-100000px';
document.body.appendChild(input);
input.value = text;
input.select();
input.setSelectionRange(0, text.length);
document.execCommand('copy');
document.body.removeChild(input);
return true;
}
"""
run_js(CLIPBOARD_SETUP)
put_button("Set clioboard", lambda: run_js("writeText(text)", text="Some text")) You can try the code in here: https://s.pywebio.online/f24f31757b10a0e74b9b874c9588fc78 |
Thank you for this example. I considered using a similar approach but was hesitant because |
Unfortunately the provided example does not work in Safari (tested in Safari version 16.3). |
貌似我在popup弹窗中操作复制不会生效,以下是代码,希望作者指引,非常感谢 ` {v} '), put_button("Set clioboard", lambda x=v: run_js("writeText(text)", text=f"{x}"))]for index, v in enumerate(valuelist, 1)], ['序号', '节点名称', '操作'],scope='aaa').style( "user-select: text; -webkit-user-select: text; " "-moz-user-select: text; -ms-user-select: " "text;") ` |
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: