Skip to content

Fix Copy button fails in Safari#181

Open
fcakyon wants to merge 1 commit intomainfrom
fix/safari-clipboard
Open

Fix Copy button fails in Safari#181
fcakyon wants to merge 1 commit intomainfrom
fix/safari-clipboard

Conversation

@fcakyon
Copy link
Member

@fcakyon fcakyon commented Jan 21, 2026

Summary

  • The "Copy page in Markdown format" button works in Chrome, Edge, and Firefox but fails in Safari with "Failed" message
  • Safari has stricter Clipboard API security that rejects writes when async operations (like fetch) occur before the clipboard write
  • Switch from navigator.clipboard.writeText() to ClipboardItem API which reserves clipboard permission at click time while content loads asynchronously
  • This approach works across all modern browsers including Safari

Test

Tested on Safari 18 - button now shows "Copied!" and markdown content is correctly copied to clipboard.

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Fixes Safari clipboard copy failures by switching to ClipboardItem-based async content generation. 🧩

📊 Key Changes

  • Refactored the markdown fetch/format logic into an async getContent() helper
  • Replaced navigator.clipboard.writeText(...) with navigator.clipboard.write([new ClipboardItem(...)])
  • Ensured front-matter stripping and title/source header generation remain intact

🎯 Purpose & Impact

  • Improves cross-browser compatibility, specifically resolving copy-button failures in Safari 🧭
  • Provides more reliable clipboard writes for generated markdown content 📋
  • Keeps user experience consistent by maintaining the same “Copied!” feedback behavior ✅

The writeText() API works in Chrome, Edge, and Firefox but fails in
Safari due to stricter user gesture requirements. Safari rejects
clipboard writes when async operations (fetch) occur before the write.

Switch to ClipboardItem API which reserves clipboard permission at
click time while content loads asynchronously. This approach works
across all modern browsers including Safari.
@fcakyon fcakyon self-assigned this Jan 21, 2026
@UltralyticsAssistant UltralyticsAssistant added bug Something isn't working fixed Bug has been resolved labels Jan 21, 2026
@UltralyticsAssistant
Copy link
Member

👋 Hello @fcakyon, thank you for submitting a ultralytics/mkdocs 🚀 PR! This is an automated message to help with review—an Ultralytics engineer will assist shortly. 🛠️

-✅ Define a Purpose: Clearly explain the purpose of your fix or feature in your PR description, and link to any relevant issues. Ensure your commit messages are clear, concise, and adhere to the project's conventions.
-✅ Synchronize with Source: Confirm your PR is synchronized with the ultralytics/mkdocs main branch. If it's behind, update it by clicking the 'Update branch' button or by running git pull and git merge main locally.
-✅ Ensure CI Checks Pass: Verify all Ultralytics Continuous Integration (CI) checks are passing. If any checks fail, please address the issues.
-✅ Update Documentation: Update the relevant documentation for any new or modified features.
-✅ Add Tests: If applicable, include or update tests to cover your changes, and confirm that all tests are passing.
-✅ Sign the CLA: Please ensure you have signed our Contributor License Agreement if this is your first Ultralytics PR by writing "I have read the CLA Document and I sign the CLA" in a new message.
-✅ Minimize Changes: Limit your changes to the minimum necessary for your bug fix or feature addition. "It is not daily increase but daily decrease, hack away the unessential. The closer to the source, the less wastage there is." — Bruce Lee

For more guidance, please refer to our Contributing Guide. Don't hesitate to leave a comment if you have any questions. Thank you for contributing to Ultralytics! 🚀

Copy link
Member

@UltralyticsAssistant UltralyticsAssistant left a comment

Choose a reason for hiding this comment

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

🔍 PR Review

Made with ❤️ by Ultralytics Actions

Looks clean—no issues found based on the diff. The refactor to async content generation and ClipboardItem usage appears safe and consistent with existing behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fixed Bug has been resolved

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants