修复在HTTP/非安全上下文环境下,复制rss link失效的问题 - #1091
Open
afraidjpg wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
该 PR 针对在非 HTTPS / 非安全上下文(例如家庭局域网通过 IP:端口访问)下浏览器禁用 navigator.clipboard.writeText 导致 RSS 链接无法复制的问题,引入带回退方案的复制实现以恢复 WebUI 的复制功能(对应 Issue #1090)。
Changes:
- 将 RSS 链接复制从直接调用
navigator.clipboard.writeText改为使用带 fallback 的复制方法。 - 新增
copyTextWithFallback:优先使用 Clipboard API(安全上下文),失败时回退到document.execCommand('copy')。
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
58
to
62
| if (!link) return; | ||
| await navigator.clipboard.writeText(link); | ||
| await copyTextWithFallback(link); | ||
| copied.value = true; | ||
| clearTimeout(copyTimer); | ||
| copyTimer = setTimeout(() => { |
Comment on lines
+84
to
+88
| await navigator.clipboard.writeText(text); | ||
| return true; | ||
| } | ||
| } catch { | ||
| } |
Comment on lines
+90
to
+107
| // fallback 方案:创建一个不可见的 textarea 元素,选中内容并执行复制命令 | ||
| const textarea = document.createElement("textarea"); | ||
| textarea.value = text; | ||
| textarea.style.position = "fixed"; | ||
| textarea.style.left = "-9999px"; | ||
| textarea.style.top = "-9999px"; | ||
| textarea.setAttribute("readonly", ""); | ||
|
|
||
| document.body.appendChild(textarea); | ||
|
|
||
| textarea.select(); | ||
| textarea.setSelectionRange(0, textarea.value.length); | ||
|
|
||
| const success = document.execCommand("copy"); | ||
|
|
||
| document.body.removeChild(textarea); | ||
|
|
||
| return success; |
|
@afraidjpg is attempting to deploy a commit to the estrellaxd's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
非 HTTPS / 安全上下文 环境下,chrome等浏览器会禁用
navigator.clipboard.writeText且无法在网站设置中更改此设置,导致在家庭局域网的无https的环境下无法使用复制功能[错误报告]非HTTPS下无法使用rss链接复制功能 #1090