Skip to content

fix(theme): add clipboard fallback for non-HTTPS environments#11792

Open
io-ing wants to merge 1 commit intofacebook:mainfrom
io-ing:fix/copy-button-non-https-fallback
Open

fix(theme): add clipboard fallback for non-HTTPS environments#11792
io-ing wants to merge 1 commit intofacebook:mainfrom
io-ing:fix/copy-button-non-https-fallback

Conversation

@io-ing
Copy link

@io-ing io-ing commented Mar 10, 2026

navigator.clipboard is undefined in non-HTTPS contexts (e.g. accessing dev server via LAN IP like http://192.168.x.x:3000), which causes the copy button to throw an error since #11422 removed the copy-text-to-clipboard fallback.

This PR adds a textarea-based fallback when navigator.clipboard is unavailable.

Fixes 11791

@meta-cla
Copy link

meta-cla bot commented Mar 10, 2026

Hi @io-ing!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@netlify
Copy link

netlify bot commented Mar 10, 2026

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit 0e17ed4
🔍 Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/69b020f35753250008ef7c51
😎 Deploy Preview https://deploy-preview-11792--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

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

I would prefer re-introducing copy-text-to-clipboard
because it handles quirks we don't want to deal with

We could eventually lazy load it with a dynamic import so that it doesn't need to load/init for users who are using https

return;
}

// Fallback for non-HTTPS environments where navigator.clipboard is unavailable
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this doesn't work, I'd rather revert to the former lib we were using, that handles quirks too

@meta-cla
Copy link

meta-cla bot commented Mar 10, 2026

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla bot added the CLA Signed Signed Facebook CLA label Mar 10, 2026
@io-ing io-ing force-pushed the fix/copy-button-non-https-fallback branch 2 times, most recently from 091cb1b to 65038ae Compare March 10, 2026 13:39
@socket-security
Copy link

socket-security bot commented Mar 10, 2026

@io-ing io-ing force-pushed the fix/copy-button-non-https-fallback branch from 65038ae to 0e17ed4 Compare March 10, 2026 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Signed Facebook CLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CopyButton throws "Cannot read properties of undefined (reading 'writeText')" in non-HTTPS environments after 3.9.x

2 participants