Loading
Migrate navigator.clipboard in link bubble menu to copyToClipboard
What does this MR do and why?
The link bubble menu copy button called navigator.clipboard.writeText directly, which fails in non-secure contexts.
This follows the work in !211222 (merged), which blocks direct use of navigator.clipboard. The component now uses the shared helper copyToClipboard from ~/lib/utils/copy_to_clipboard and the matching eslint-disable comment is removed. The spec now mocks copyToClipboard instead of spying on navigator.clipboard.
Closes #579482.
References
Part of epic &19827.
Screenshots or screen recordings
Not applicable — no visual change.
How to set up and validate locally
- Run
yarn jest spec/frontend/content_editor/components/bubble_menus/link_bubble_menu_spec.js. - In GDK, open a project wiki page (or an issue description) and switch to the rich text editor.
- Add a link, for example
[GitLab](https://gitlab.com), and select the link text to open the link bubble menu. - Select Copy link URL and paste into another field. The full URL is pasted.
- Upload a file (for example a PDF) in the same editor, select its link, and select Copy link URL.
The pasted value is the full absolute URL, not the relative
/uploads/...path. - Optional, non-secure context: open GDK over plain HTTP on an address other than
localhost(for examplehttp://<your-LAN-IP>:3000). Therenavigator.clipboardisundefined, so before this change the button threw aTypeErrorand nothing was copied. With this change,copyToClipboardfalls back todocument.execCommand('copy')and the URL is copied.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist.
This contribution was prepared with the help of an AI assistant. I reviewed the changes and take responsibility for them.
Edited by Anish Kumar