Improve copy page functionality with fallback and DOM content#24
Merged
Improve copy page functionality with fallback and DOM content#24
Conversation
Two bugs: (1) fetch response status wasn't checked, so a 404 from GitHub raw would silently copy error HTML instead of markdown content, and (2) navigator.clipboard.writeText can fail in non-secure contexts with no fallback. Now checks res.ok, falls back to DOM text content when fetch fails, and uses textarea+execCommand as a clipboard fallback. https://claude.ai/code/session_01K6L2NgGxXGWePYRUSi8qW2
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.
Summary
Enhanced the copy page button to be more robust by adding a fallback clipboard mechanism and implementing a graceful degradation strategy when fetching remote content fails.
Key Changes
fallbackCopy()function using the legacydocument.execCommand('copy')API for browsers that don't support the modern Clipboard APIwriteToClipboard()function that attempts to use the modern Clipboard API with automatic fallback to the legacy methodcopyPage()to gracefully handle fetch failures by falling back to copying the page's DOM content (.vp-docelement text) or the current URLImplementation Details
res.ok) before processing the response.vp-docelement and trims whitespace for cleaner copyinghttps://claude.ai/code/session_01K6L2NgGxXGWePYRUSi8qW2