Merged
Conversation
Member
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||
33b5399 to
8831a28
Compare
klmhyeonwoo
approved these changes
Sep 11, 2025
Comment on lines
+20
to
+39
| const textArea = document.createElement("textarea"); | ||
| textArea.value = text; | ||
|
|
||
| textArea.style.position = "fixed"; | ||
| textArea.style.top = "-9999px"; | ||
| textArea.style.left = "-9999px"; | ||
|
|
||
| document.body.appendChild(textArea); | ||
| textArea.focus(); | ||
| textArea.select(); | ||
|
|
||
| try { | ||
| const successful = document.execCommand("copy"); | ||
| document.body.removeChild(textArea); | ||
|
|
||
| return successful; | ||
| } catch (execError) { | ||
| document.body.removeChild(textArea); | ||
|
|
||
| return false; |
Member
There was a problem hiding this comment.
우와.. 지원하지 않는 브라우저의 경우이거나 에러가 발생하는 경우에는 execCommand로 처리하셨군요! 굿!
| */ | ||
| export default async function copyToClipboard(text: string): Promise<boolean> { | ||
| try { | ||
| if (text.length > 1000000) { |
Member
Author
There was a problem hiding this comment.
요거는 1,000,000 = 1MB로 제한한 거에요..!!
구현하고, 마지막에 gpt한테 코드에 아쉬운 점을 물어봤었는데요!!
브라우저별로 clipboard api에 제한이 있다는 사실을 알게 되었어요!
chrome이 약 20mb, firefox와 safari가 약 1mb라는 사실을 알려줘서 저렇게 추가했어요!
그런데, 말씀대로 숫자에 대한 정보가 명확하지 않다보니, 주석 + 별도의 처리가 필요해보여서 아래와 같이 수정했어요!
if (text.length > 1024 * 1024) {
throw new Error("Text too large to copy (max 1MB)");
}
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.
Description
웹 애플리케이션에서 텍스트를 클립보드에 복사하는 기능을 제공하는
copyToClipboard유틸리티 함수를 추가합니다.최신 Clipboard API를 우선적으로 사용하고, 지원하지 않는 환경에서는 레거시 방식으로 자동 대체하여 높은 브라우저 호환성을 제공합니다.
또한 대용량 텍스트에 대한 안전장치를 구현하여 안정성을 높였습니다.