Skip to content

fix(client): add clipboard fallback for insecure contexts.#362

Open
Star-Trowa wants to merge 3 commits into
bookorbit:mainfrom
Star-Trowa:BO-204-clipboard-fallback-insecure-context
Open

fix(client): add clipboard fallback for insecure contexts.#362
Star-Trowa wants to merge 3 commits into
bookorbit:mainfrom
Star-Trowa:BO-204-clipboard-fallback-insecure-context

Conversation

@Star-Trowa

@Star-Trowa Star-Trowa commented Jun 17, 2026

Copy link
Copy Markdown

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

  • I've read through my own diff
  • This PR was discussed in an issue (is a bug)
  • Lint and tests pass locally
  • No unintended files included (build artifacts, .env, personal configs)

Summary by CodeRabbit

  • Refactor
    • Improved copy-to-clipboard behavior by centralizing the logic into a shared utility with a modern method plus a legacy fallback for broader compatibility.
    • Updated settings copy actions to provide clear success/error feedback based on whether the copy succeeded.
    • Ensured table keyboard copy operations use the same reliable clipboard helper.

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
@github-actions github-actions Bot added the client Changes affecting the client application or frontend behavior. label Jun 17, 2026
@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

An error occurred during the review process. Please try again later.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 46ef4bd3-dfe9-427f-97ce-7baf2256dbf6

📥 Commits

Reviewing files that changed from the base of the PR and between 523543d and d50903f.

📒 Files selected for processing (3)
  • client/src/features/book/composables/useTableKeyboard.ts
  • client/src/features/settings/OpdsSettings.vue
  • client/src/lib/clipboard.ts

📝 Walkthrough

Walkthrough

A new shared clipboard utility centralizes clipboard handling across multiple components. copyToClipboard exports an async function that attempts the modern Clipboard API and falls back to a hidden textarea with document.execCommand('copy'), returning a boolean result. OpdsSettings and useTableKeyboard both migrate to use this utility instead of their previous local clipboard implementations.

Changes

Clipboard Utility Consolidation

Layer / File(s) Summary
Shared clipboard utility with fallback strategy
client/src/lib/clipboard.ts
New copyToClipboard(text: string): Promise<boolean> attempts modern navigator.clipboard.writeText, falls back to hidden textarea + document.execCommand('copy'), and returns boolean success/failure. Guards against unsupported environments.
OpdsSettings clipboard integration with error handling
client/src/features/settings/OpdsSettings.vue
Imports shared copyToClipboard and refactors copyUrl() and copyValue() to await the utility and conditionally emit success or error toasts based on the boolean result.
useTableKeyboard keyboard shortcut delegation
client/src/features/book/composables/useTableKeyboard.ts
Removes local clipboard implementation, imports shared copyToClipboard, and delegates row/cell copy operations to the centralized utility while preserving keyboard shortcut behavior.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐇 From settings to tables, clipboard calls spread,
Now unified fallback logic instead!
Modern API first, textarea for the rest,
A copy that works across every test. ✂️
One util to bind them, reliable and neat,
The OPDS bug fixed — success is complete! 🎯

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding a clipboard fallback for insecure HTTP contexts where navigator.clipboard is unavailable.
Description check ✅ Passed The description covers what was done, testing approach, and includes before/after evidence. Most checklist items are incomplete, but core information is present and complete.
Linked Issues check ✅ Passed The PR fully addresses issue #204 by implementing a clipboard fallback mechanism for HTTP contexts, ensuring the copy button works across both HTTPS and HTTP connections as required.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the clipboard functionality issue. The refactoring to create a shared clipboard utility is part of the fix, not an out-of-scope change.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 72a42e0 and 523543d.

📒 Files selected for processing (1)
  • client/src/features/settings/OpdsSettings.vue

Comment thread client/src/features/settings/OpdsSettings.vue Outdated
@neonsolstice

Copy link
Copy Markdown
Collaborator

@Star-Trowa

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.

@Star-Trowa

Copy link
Copy Markdown
Author

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.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

client Changes affecting the client application or frontend behavior.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Copy button on OPDS Page not working

2 participants