Have you read the Contributing Guidelines on issues?
Prerequisites
Description
Bug Report
Docusaurus version: 3.9.2
Node version: v20.19.5
Browser: chrome 145.0.7632.116
Problem
After upgrading from 3.8.x to 3.9.x, the code block copy button throws an error when the site is accessed via a non-HTTPS local network address (e.g.
http://192.168.x.x:3000).
TypeError: Cannot read properties of undefined (reading 'writeText')
at CopyButton/index.js
Root Cause
PR #11422 replaced copy-text-to-clipboard with the native navigator.clipboard.writeText() API. However, navigator.clipboard is undefined in non-HTTPS contexts
(except localhost). The old library had a <textarea> fallback that handled this case.
Reproducible demo
No response
Steps to reproduce
- Run
npm run start -- --host 0.0.0.0
- Access the site from another device on the same LAN via
http://192.168.x.x:3000
- Click the copy button on any code block
Expected behavior
Code is copied to clipboard successfully.
Actual behavior
The copy button throws an error and nothing is copied:
TypeError: Cannot read properties of undefined (reading 'writeText')
at CopyButton/index.js
Your environment
- Public source code: N/A
- Public site URL: N/A
- Docusaurus version used: 3.9.2
- Environment name and version: Node.js v20.19.5, Chrome 145.0.7632.116
- Operating system and version: Ubuntu 20.04 LTS
Self-service
Have you read the Contributing Guidelines on issues?
Prerequisites
npm run clearoryarn clearcommand.rm -rf node_modules yarn.lock package-lock.jsonand re-installing packages.Description
Bug Report
Docusaurus version: 3.9.2
Node version: v20.19.5
Browser: chrome 145.0.7632.116
Problem
After upgrading from 3.8.x to 3.9.x, the code block copy button throws an error when the site is accessed via a non-HTTPS local network address (e.g.
http://192.168.x.x:3000).TypeError: Cannot read properties of undefined (reading 'writeText')
at CopyButton/index.js
Root Cause
PR #11422 replaced
copy-text-to-clipboardwith the nativenavigator.clipboard.writeText()API. However,navigator.clipboardisundefinedin non-HTTPS contexts(except
localhost). The old library had a<textarea>fallback that handled this case.Reproducible demo
No response
Steps to reproduce
npm run start -- --host 0.0.0.0http://192.168.x.x:3000Expected behavior
Code is copied to clipboard successfully.
Actual behavior
The copy button throws an error and nothing is copied:
TypeError: Cannot read properties of undefined (reading 'writeText')
at CopyButton/index.js
Your environment
Self-service