Changelog - 2026-11-04
BrowserClipboard writes and reads the clipboard outside React
New FeatureIn one line. BrowserClipboard.writeText({ text }) and BrowserClipboard.readText() write and read the text on the clipboard from any code, a service, a util or a toast action, and answer false or undefined where the browser refuses. They never throw and never reject.
The example is in Browser clipboard.
What changed
BrowserClipboard.writeText({ text })answerstruewhen the text is on the clipboard.BrowserClipboard.readText()answers the text, orundefined. Reading needs a permission and a user gesture, and some browsers do not offer it, soundefinedis a normal answer.- Every refusal is an answer, not an error. No
navigator(a server render), nonavigator.clipboard(an insecure context, an old WebView), a denied permission, no user gesture, a document that is not focused, and a thrown error all givefalseorundefined. - No fallback and no logging. The helper does not use
document.execCommand('copy')(deprecated, needs a DOM node) and logs nothing, so the caller decides what to show. useCopyToClipboardcalls the helper. It returns{ copy, isCopied }(see theisCopiedentry), and still logs a warning when the text is not copied. It also no longer throws aReferenceErrorwherenavigatoris not declared, such as a server render.
Who is affected
- An app that calls
navigator.clipboarditself outside React, with its own handling of the cases above. You can callBrowserClipboardinstead and delete that handling. - An app that renders
useCopyToClipboardon a server.copynow resolvesfalsethere instead of throwing. - All other apps. No action needed.
See Browser clipboard and Hooks.