fix(client): add clipboard fallback for insecure contexts.#362
fix(client): add clipboard fallback for insecure contexts.#362Star-Trowa wants to merge 3 commits into
Conversation
navigator.clipboard is undefined when accessing BookOrbit over plain
HTTP. Add a secureCopy helper that falls back to
execCommand('copy') when the Clipboard API is unavailable.
Closes bookorbit#204
|
Caution Review failedAn error occurred during the review process. Please try again later. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughA new shared clipboard utility centralizes clipboard handling across multiple components. ChangesClipboard Utility Consolidation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@client/src/features/settings/OpdsSettings.vue`:
- Around line 85-86: The code calls secureCopy() but ignores its return value,
always showing a success toast regardless of whether the copy operation actually
succeeded or failed. Modify all calls to secureCopy() (at the locations
mentioned: around lines 85-86, 179-180, and 183-190) to check the returned
boolean value. Only display the success toast when secureCopy() returns true,
and add appropriate error handling (such as an error toast) for when it returns
false to properly inform users of copy failures.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 00b788c2-3213-4f36-9dcb-232b62859da1
📒 Files selected for processing (1)
client/src/features/settings/OpdsSettings.vue
|
Nice work, this fixes it. One thing though. we already have basically this same fallback in useTableKeyboard.ts (copyToClipboard), so could you pull it into a shared lib/clipboard.ts and use it in both spots instead of a second copy? Also the secureCopy return value is ignored right now, so a failed copy still shows the success toast. |
|
Yes I was on the fence whether I should refactor the old files, but got it. I will push another commit with the changes. Thanks for reviewing. |
…-204-clipboard-fallback-insecure-context
navigator.clipboard is undefined when accessing BookOrbit over plain
HTTP on a local network. Extract a shared copyToClipboard helper into
lib/clipboard.ts that falls back to execCommand('copy') when the
Clipboard API is unavailable.
Closes bookorbit#204
What does this PR do?
navigator.clipboard is undefined when accessing BookOrbit over plain HTTP. Add a secureCopy helper that falls back to
execCommand('copy') when the Clipboard API is unavailable.
Closes #204
How did you test this?
Set up local dev environment, spun up Docker, added a book, confirmed it shows in the library. Tested happy day scenarios, like reading book, adding metadata, browsing the website. Checked the fix on firefox and edge browsers, using both localhost url (where the bug was not visible), and http://ip:port url (where the bug was visible due to plain http).
Verified in code that this clipboard fix is acceptable, and already in use in similar way for a different feature.
Ran the verify command. Read the contributing and testing docs before creating the PR.
Screenshots
Before
https://github.com/user-attachments/assets/dfd5b3d5-33e5-4ee6-8343-1fd0837faae7
Nothing happens on clicking the Copy button. Using book orbit self-hosted via tailscale.
After
https://github.com/user-attachments/assets/9ab235ec-95b1-4555-ab80-81a24b047519
Copy works fine now for both https and http urls.
Anything non-obvious in the diff?
No.
Checklist
.env, personal configs)Summary by CodeRabbit