Skip to content
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

Copy of code blocks does not work for LAN access #4324

Closed
1 task done
Kilig947 opened this issue May 23, 2023 · 7 comments · Fixed by #4350
Closed
1 task done

Copy of code blocks does not work for LAN access #4324

Kilig947 opened this issue May 23, 2023 · 7 comments · Fixed by #4350
Labels
bug Something isn't working pending clarification

Comments

@Kilig947
Copy link

Describe the bug

When I access my application on the LAN and click the copy button in the code block, an error is reported
If I access localhost, the problem will no longer exist
Please fix it as soon as possible
image

Is there an existing issue for this?

  • I have searched the existing issues

Reproduction

.launch(server_name="0.0.0.0"

Screenshot

No response

Logs

properties of undefined (reading 'writeText')
    at HTMLButtonElement.<anonymous> (ChatBot.svelte:57:25)
(匿名) @ ChatBot.svelte:57
ChatBot.svelte:5

System Info

no

Severity

annoying

@Kilig947 Kilig947 added the bug Something isn't working label May 23, 2023
@Kilig947
Copy link
Author

This error is due to the browser security policy that does not allow the navigator.clipboard.writeText() method when accessing on a LAN. This is to prevent malicious websites from abusing the clipboard function.

The reason it works properly when accessed locally is that the local environment is considered a trusted environment and therefore the clipboard API can be used.

To solve this problem, you can use a library or technology such as clipboard.js, which provides cross-browser clipboard functionality and is not restricted by browser security policies. The following is sample code for using clipboard.js:

  1. First, you need to introduce the clipboard.js library. You can download the library from the official website, or use the CDN link: ``clipboard.js`:
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.8/clipboard.min.js"></script>
  1. Then, in your code, replace the following code:
navigator.clipboard.writeText(code_node.innerText.trimEnd()).

for:

const clipboard = new ClipboardJS(button, {
  text: function() {
    return code_node.innerText.trimEnd().
  }
}).

Make sure you have properly introduced the clipboard.js library and added it to the handler for the button click event.

By using clipboard.js, you can use the clipboard functionality properly in a LAN environment while avoiding the restrictions of browser security policies.

Translated with www.DeepL.com/Translator (free version)

@abidlabs
Copy link
Member

Hi @Kilig947 it looks like you are using an older version of Gradio. Can you confirm if this is still an issue in the latest version of gradio (3.32)?

@Kilig947
Copy link
Author

Hi @Kilig947 it looks like you are using an older version of Gradio. Can you confirm if this is still an issue in the latest version of gradio (3.32)?
Is drawing HTML code no longer supported in 3.32.0 chatbot? If I throw the HTML code to chatbot, it will display it directly in source code 🥲 🥲 🥲 🥲 🥲

image
image

@Kilig947
Copy link
Author

demo.queue(concurrency_count=CONCURRENT_COUNT).launch(server_name=f"{func_box.ipaddr()}", share=True, server_port=PORT, auth=AUTHENTICATION)
The start-up parameters are as above, and when the copy button is clicked, no error is reported, but the copy is not successful either🥲

image

@Kilig947
Copy link
Author

(Light theme): http://localhost:7891
(dark theme): http://10.13.78.56:7891/? __theme=dark

Both in 3.28.3 and 3.32.0, when I visit http://localhost:7891, the copy button works fine, but when I visit http://10.13.78.56:7891/? __theme=dark, the copy button does not work properly

demo.queue(concurrency_count=CONCURRENT_COUNT).launch(server_name=f"{func_box.ipaddr()}", share=True, server_port=PORT, auth=AUTHENTICATION) The start-up parameters are as above, and when the copy button is clicked, no error is reported, but the copy is not successful either🥲

image

@binary-husky
Copy link
Contributor

I have fixed this issue in #4350

@Kilig947 @abidlabs

@Kilig947
Copy link
Author

大佬牛皮

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pending clarification
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants